TALP-UPC / FreeLing

FreeLing project source code
Other
252 stars 96 forks source link

Ruby API working on Ubuntu 18.04 #81

Closed andreaslillebo closed 5 years ago

andreaslillebo commented 5 years ago

I was able to get the ruby API to work. I'm sharing what I did so that it may help others and so that others can help improve this solution.

I used the following software versions:

1) Edit APIs/ruby/Makefile:

So far everything appears to be working. I would have submitted a PR, but I don't know how to properly fix these errors.

lluisp commented 5 years ago

Great! thanks!

I included your changes to APIs/ruby/Makefile in git master branch. Please check if it works for you and let me know.

Note that you may need to provide some customized variables when calling make. E.g.: make FREELINGDIR=/my/freeling/dir RUBYVER=ruby-2.5.0

If default values in the Makefile suit you, you can just run simply "make"

I tried that in ubuntu 16. If your distro/version installs ruby in some different paths, you may need to adapt some of the paths in the g++ command in the Makefile.

I also fixed the crfsuite include organization so it is no longer needed to add that path when building the API. You will need to recompile and reinstall FreeLing for this to work (or you can just keep the path in the Makefile)

lluisp commented 5 years ago

I added your modifications to APIs/ruby/Makefile please try them and let me know if they work for you.

I also reorganized crfsuite includes so it is no longer needed to add that path to the g++ command when building the API. (you will need to rebuild and reinstall FreeLing for this to work though... you may want to keep the path there for a while)

andreaslillebo commented 5 years ago

Thanks.

I pulled the latest master, recompiled FreeLing and the ruby API, and it works.

As you mentioned, I had to change RUBYDIR = /home/andreas/.rbenv/versions/2.5.1/include/$(RUBYVER).

I also had to add the -I$(RUBYDIR)/x86_64-linux include flag in the make file (otherwise it wouldn't find ruby/config.h):

g++ -shared -o freeling.so freeling_rubyAPI.cxx -lfreeling -I$(FREELINGDIR)/include -L$(FREELINGDIR)/lib -I$(RUBYDIR) -I$(RUBYDIR)/x86_64-linux -I/usr/include/x86_64-linux-gnu/$(RUBYVER) -fPIC -std=gnu++0x

It seems like the paths vary a bit depending on how ruby was installed (system/rbenv/rvm/etc.). It seems like it might be possible to set all of these automatically for any system using ruby's mkmf (MakeMakeFile): https://github.com/ruby/ruby/blob/trunk/doc/extension.rdoc#prepare-extconfrb https://silverhammermba.github.io/emberb/extend/

This is how many ruby gems with C-extensions do it, i.e. Nokogiri: https://github.com/sparklemotion/nokogiri/blob/b3750eb71e101287aa0e7a231232222c7213b3f3/ext/nokogiri/extconf.rb

lluisp commented 5 years ago

OK thanks. By now I will add both paths and a comment in the makefile. Since this Makefile is just a hack, I don't want to elaborate too much on it, unless until SWIG properly generates the API. In any case, I guess that eventually CMake will take care of these things automatically, so let's wait for now.

thanks!