ankane / or-tools-ruby

Operations research tools for Ruby
Apache License 2.0
173 stars 22 forks source link

Unable to find OR-Tools when installing gem locally #5

Closed rodreegez closed 4 years ago

rodreegez commented 4 years ago

Hey there,

I'm trying to get the gem setup for further local development, however I'm having trouble getting it to find OR-Tools.

I'm following the instructions in the README, which are:

git clone https://github.com/ankane/or-tools.git
cd or-tools
bundle install
bundle exec rake compile
bundle exec rake test

I can clone, cd and bundle install fine, but when I run bundle exec rake compile, I get the following error:

$ bundle exec rake install
or-tools 0.2.0 built to pkg/or-tools-0.2.0.gem.rake aborted!
Couldn't install gem, run `gem install /home/rodreegez/Projects/or-tools/pkg/or-tools-0.2.0.gem' for more detailed output/home/rodreegez/.asdf/installs/ruby/2.7.1/bin/bundle:23:in `load'
/home/rodreegez/.asdf/installs/ruby/2.7.1/bin/bundle:23:in `<main>'
Tasks: TOP => install
(See full trace by running task with --trace)

Just gem installing as the error suggests gives me the following error:

$ gem install /home/rodreegez/Projects/or-tools/pkg/or-tools-0.2.0.gem
Building native extensions. This could take a while...ERROR:  Error installing /home/rodreegez/Projects/or-tools/pkg/or-tools-0.2.0.gem:
    ERROR: Failed to build gem native extension.    current directory: /home/rodreegez/.asdf/installs/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/or-tools-0.2.0/ext/or-tools
/home/rodreegez/.asdf/installs/ruby/2.7.1/bin/ruby -I /home/rodreegez/.asdf/installs/ruby/2.7.1/lib/ruby/2.7.0 -r ./siteconf20200720-22754-z3hyz7.rb extconf.rb
checking for -lstdc++... yes
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/home/rodreegez/.asdf/installs/ruby/2.7.1/bin/$(RUBY_BASE_NAME)
    --with-libpath
    --without-libpath
    --with-stdc++-dir
    --without-stdc++-dir
    --with-stdc++-include
    --without-stdc++-include=${stdc++-dir}/include
    --with-stdc++-lib
    --without-stdc++-lib=${stdc++-dir}/lib
    --with-stdc++lib
    --without-stdc++lib
    --with-or-tools-dir
    --without-or-tools-dir
    --with-or-tools-include
    --without-or-tools-include=${or-tools-dir}/include
    --with-or-tools-lib
    --without-or-tools-lib=${or-tools-dir}/lib
/home/rodreegez/.asdf/installs/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/or-tools-0.2.0/ext/or-tools/vendor.rb:29:in `<top (required)>': Binary installation not available for this platform. (RuntimeError)

Build the OR-Tools C++ library from source, then run:
bundle config build.or-tools --with-or-tools-dir=/path/to/or-tools

    from extconf.rb:17:in `require_relative'
    from extconf.rb:17:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /home/rodreegez/.asdf/installs/ruby/2.7.1/lib/ruby/gems/2.7.0/extensions/x86_64-linux/2.7.0/or-tools-0.2.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/rodreegez/.asdf/installs/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/or-tools-0.2.0 for inspection.
Results logged to /home/rodreegez/.asdf/installs/ruby/2.7.1/lib/ruby/gems/2.7.0/extensions/x86_64-linux/2.7.0/or-tools-0.2.0/gem_make.out

I clocked the error message about telling bundler where to find OR-Tools, so I ran:

bundle config build.or-tools --with-or-tools-dir=/home/rodreegez/src/or-tools/or-tools_Ubuntu-20.04-64bit_v7.7.7810

Running bundle exec rake install yeilds the same error (which I'm not all that surprised about).

The mkmf.log doesn't seem to be all that enlightening, but I include it here just in case:

mkmf.log ``` $ cat /home/rodreegez/.asdf/installs/ruby/2.7.1/lib/ruby/gems/2.7.0/extensions/x86_64-linux/2.7.0/or-tools-0.2.0/mkmf.log have_library: checking for -lstdc++... -------------------- yes "g++ -o conftest -I/home/rodreegez/.asdf/installs/ruby/2.7.1/include/ruby-2.7.0/x86_64-linux -I/home/rodreegez/.asdf/installs/ruby/2.7.1/include/ruby-2.7.0/ruby/backward -I/home/rodreegez/.asdf/installs/ruby/2.7.1/include/ruby-2.7.0 -I. -I/home/rodreegez/.asdf/installs/ruby/2.7.1/include -I/home/rodreegez/.asdf/installs/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/rice-2.2.0/ruby/lib/include -g -O2 conftest.c -L. -L/home/rodreegez/.asdf/installs/ruby/2.7.1/lib -Wl,-rpath,/home/rodreegez/.asdf/installs/ruby/2.7.1/lib -L. -L/home/rodreegez/.asdf/installs/ruby/2.7.1/lib -fstack-protector-strong -rdynamic -Wl,-export-dynamic -L/home/rodreegez/.asdf/installs/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/rice-2.2.0/ruby/lib/lib -lrice -Wl,-rpath,/home/rodreegez/.asdf/installs/ruby/2.7.1/lib -L/home/rodreegez/.asdf/installs/ruby/2.7.1/lib -lruby -lm -lc" checked program was: /* begin */ 1: #include "ruby.h" 2: 3: int main(int argc, char **argv) 4: { 5: return !!argv[argc]; 6: } /* end */ "g++ -o conftest -I/home/rodreegez/.asdf/installs/ruby/2.7.1/include/ruby-2.7.0/x86_64-linux -I/home/rodreegez/.asdf/installs/ruby/2.7.1/include/ruby-2.7.0/ruby/backward -I/home/rodreegez/.asdf/installs/ruby/2.7.1/include/ruby-2.7.0 -I. -I/home/rodreegez/.asdf/installs/ruby/2.7.1/include -I/home/rodreegez/.asdf/installs/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/rice-2.2.0/ruby/lib/include -g -O2 conftest.c -L. -L/home/rodreegez/.asdf/installs/ruby/2.7.1/lib -Wl,-rpath,/home/rodreegez/.asdf/installs/ruby/2.7.1/lib -L. -L/home/rodreegez/.asdf/installs/ruby/2.7.1/lib -fstack-protector-strong -rdynamic -Wl,-export-dynamic -L/home/rodreegez/.asdf/installs/ruby/2.7.1/lib/ruby/gems/2.7.0/gems/rice-2.2.0/ruby/lib/lib -lrice -Wl,-rpath,/home/rodreegez/.asdf/installs/ruby/2.7.1/lib -L/home/rodreegez/.asdf/installs/ruby/2.7.1/lib -lruby -lstdc++ -lm -lc" checked program was: /* begin */ 1: #include "ruby.h" 2: 3: /*top*/ 4: extern int t(void); 5: int main(int argc, char **argv) 6: { 7: if (argc > 1000000) { 8: int (* volatile tp)(void)=(int (*)(void))&t; 9: printf("%d", (*tp)()); 10: } 11: 12: return !!argv[argc]; 13: } 14: 15: int t(void) { ; return 0; } /* end */ -------------------- ```

I'm running Pop OS locally and have a rails app with the or-tools gem running just fine. Pop is based off of Ubuntu, and the version I'm running is specifically based off of 20.04. There is a 20.04 version of the OR Tools binary available. I did do some mad stuff in /ext/or-tools/vendor.rb to try and have the gem vendor the Ubuntu 20.04 OR Tools binary but that didn't seem to work either and I think is perhaps deviating away from the core issue?

(p.s. I wonder if the script should check lsb_release -cs and grab the codename of the OS rather than the Distributor ID? I think that would mean the gem would install more liberally on the various ubuntu-a-likes? Dunno, might be a whole new world of pain).

I feel like passing in the --with-or-tools-dir used to work but maybe since the vendoring stuff went in perhaps maybe it doesn't anymore?

TLDR; I think bundle exec rake install -- --with-or-tools-lib=/path/to/or-tools should work but it doesn't seem to. Any idea what's up with that?

ankane commented 4 years ago

Hey @rodreegez, try:

bundle exec rake clobber # reset everything
bundle exec rake compile -- --with-or-tools-dir=/path/to/or-tools
bundle exec rake install

I'm not sure about the compatibility guarantees on Ubuntu-like distros, so I think manual installation is best for now.

rodreegez commented 4 years ago

Thanks for the help. I presume the issue is to do with how I have compiled OR Tools locally, and as a result the fix is beyond the scope of this gem. I did manage to get this running on Ubuntu 18.04 proper (the gem vendored or-tools beautifully), so closing this.