Closed andreaslillebo closed 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)
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)
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
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!
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
:RUBYDIR
to the folder containingruby.h
(runlocate ruby.h
if you don't know where it is). Since I'm usingrbenv
, mine was under/home/your_username_here/.rbenv/versions/2.5.1/include/ruby-2.5.0
.FREELINGDIR
to the folder where you installed Freeling. If you built FreeLing from source, you probably will not need to update this folder.g++ -shared -o freeling.so freeling_rubyAPI.cxx -lfreeling -I$(FREELINGDIR)/include -I$(FREELINGDIR)/include/crfsuite -L$(FREELINGDIR)/lib -I$(RUBYDIR) -I$(RUBYDIR)/x86_64-linux -fPIC -std=gnu++0x
, otherwise it would not find thecrfsuite
library.cd APIs/ruby/
, hit enter. 3) Typemake
, hit enter. You will get several errors similar to thisfreeling_rubyAPI.cxx:54433:38: error: ‘make_set_nonconst_iterator’ is not a member of ‘swig’
. 4) Edit the newly createdfreeling_rubyAPI.cxx
:make_set_nonconst_iterator
and replace them withmake_nonconst_iterator
(in my case there were 8 instances). This looks like a bug inSwig
, where there is a typo in the method names generated by Swig.make
again now, you would get another error:error: binding reference of type ‘swig::IteratorOpen_T<std::reverse_iterator<std::_Rb_tree_const_iterator<std::__cxx11::basic_string<wchar_t> > >, std::__cxx11::basic_string<wchar_t>, swig::from_oper<std::__cxx11::basic_string<wchar_t> >, swig::asval_oper<std::__cxx11::basic_string<wchar_t> > >::value_type& {aka std::__cxx11::basic_string<wchar_t>&}’ to ‘const std::__cxx11::basic_string<wchar_t>’ discards qualifiers
This can be "fixed" by changing the linevalue_type& dst = *base::current;
tovalue_type dst = *base::current;
(clearly this would have to break something somewhere, since we are changing the variable from an address to a value, but somehow it seems to work).make
again. This time the build should succeed.So far everything appears to be working. I would have submitted a PR, but I don't know how to properly fix these errors.