{"id":7342,"date":"2014-06-07T02:29:30","date_gmt":"2014-06-07T02:29:30","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/06\/07\/error-finding-opencv-shared-libraries-with-rice-ruby-on-ubuntu-12-04-collection-of-common-programming-errors\/"},"modified":"2014-06-07T02:29:30","modified_gmt":"2014-06-07T02:29:30","slug":"error-finding-opencv-shared-libraries-with-rice-ruby-on-ubuntu-12-04-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/06\/07\/error-finding-opencv-shared-libraries-with-rice-ruby-on-ubuntu-12-04-collection-of-common-programming-errors\/","title":{"rendered":"Error finding opencv shared libraries with Rice (Ruby) on Ubuntu 12.04-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m trying to correctly link OpenCV shared libraries to a ruby c++ extension and for some reason any call to have_library() is failing for the opencv libraries. I installed opencv to \/usr\/local so the header files are all in \/usr\/local\/include and the libraries are all in \/usr\/local\/lib. I&#8217;ll attach my extconf.rb and related output below.<\/p>\n<pre><code>require \"mkmf-rice\"\n\ndir_config(\"opencv_core\", \"\/usr\/local\/include\", \"\/usr\/local\/lib\")\nunless have_library(\"opencv_core\")\n    raise \"Could not find opencv_core\"\nend\n\ndir_config(\"opencv_flann\", \"\/usr\/local\/include\", \"\/usr\/local\/lib\")\nunless have_library(\"opencv_flann\")\n    raise \"Could not find opencv_flann\"\nend\n\ndir_config(\"opencv_highgui\", \"\/usr\/local\/include\", \"\/usr\/local\/lib\")\nunless have_library(\"opencv_highgui\")\n    raise \"Could not find opencv_highgui\"\nend\n\ndir_config(\"opencv_features2d\", \"\/usr\/local\/include\", \"\/usr\/local\/lib\")\nunless have_library(\"opencv_features2d\")\n    raise \"Could not find opencv_features2d\"\nend\n\ndir_config(\"opencv_nonfree\", \"\/usr\/local\/include\", \"\/usr\/local\/lib\")\nunless have_library(\"opencv_nonfree\")\n    raise \"Could not find opencv_nonfree\"\nend\n\ndir_config(\"opencv_objdetect\", \"\/usr\/local\/include\", \"\/usr\/local\/lib\")\nunless have_library(\"opencv_objdetect\")\n    raise \"Could not find opencv_objdetect\"\nend\n\ncreate_makefile(\"something\")\n<\/code><\/pre>\n<p>Running $ ruby extconf.rb outputs the following error indicating that it cannot find the shared library for opencv_core. I also tried each other library on its own and they all failed as well.<\/p>\n<pre><code>checking for main() in -lopencv_core... no\n*** extconf.rb failed ***\nCould not create Makefile due to some reason, probably lack of necessary\nlibraries and\/or headers.  Check the mkmf.log file for more details.  You may\nneed configuration options.\n\nProvided configuration options:\n    --with-opt-dir\n    --without-opt-dir\n    --with-opt-include\n    --without-opt-include=${opt-dir}\/include\n    --with-opt-lib\n    --without-opt-lib=${opt-dir}\/lib\n    --with-make-prog\n    --without-make-prog\n    --srcdir=.\n    --curdir\n    --ruby=\/home\/alec\/.rvm\/rubies\/ruby-2.0.0-p247\/bin\/ruby\n    --with-libpath\n    --without-libpath\n    --with-opencv_core-dir\n    --without-opencv_core-dir\n    --with-opencv_core-include\n    --without-opencv_core-include=${opencv_core-dir}\/include\n    --with-opencv_core-lib\n    --without-opencv_core-lib=${opencv_core-dir}\/\n    --with-opencv_corelib\n    --without-opencv_corelib\nextconf.rb:7:in `': Could not find opencv_core (RuntimeError)\n<\/code><\/pre>\n<p>And mkmf.log contains the following at the beginning:<\/p>\n<pre><code>home\/alec\/.rvm\/gems\/ruby-2.0.0-p247\/gems\/rice-1.5.1\/ruby\/lib\/mkmf-rice.rb:136:in `link_command': Use RbConfig instead of obsolete and deprecated Config.\nhave_library: checking for main() in -lopencv_core... -------------------- no\n\n\/home\/alec\/.rvm\/gems\/ruby-2.0.0-p247\/gems\/rice-1.5.1\/ruby\/lib\/mkmf-rice.rb:136:in `link_command': Use RbConfig instead of obsolete and deprecated Config.\n\/home\/alec\/.rvm\/gems\/ruby-2.0.0-p247\/gems\/rice-1.5.1\/ruby\/lib\/mkmf-rice.rb:136:in `link_command': Use RbConfig instead of obsolete and deprecated Config.\n\/home\/alec\/.rvm\/gems\/ruby-2.0.0-p247\/gems\/rice-1.5.1\/ruby\/lib\/mkmf-rice.rb:136:in `link_command': Use RbConfig instead of obsolete and deprecated Config.\n\"g++ -o conftest -I\/home\/alec\/.rvm\/rubies\/ruby-2.0.0-p247\/include\/ruby-2.0.0\/x86_64-linux -I\/home\/alec\/.rvm\/rubies\/ruby-2.0.0-p247\/include\/ruby-2.0.0\/ruby\/backward -I\/home\/alec\/.rvm\/rubies\/ruby-2.0.0-p247\/include\/ruby-2.0.0 -I. -I\/usr\/local\/include     -I\/home\/alec\/.rvm\/gems\/ruby-2.0.0-p247\/gems\/rice-1.5.1\/ruby\/lib\/include  -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration conftest.c  -L. -L\/home\/alec\/.rvm\/rubies\/ruby-2.0.0-p247\/lib -Wl,-R\/home\/alec\/.rvm\/rubies\/ruby-2.0.0-p247\/lib -L\/usr\/local\/lib -Wl,-R\/usr\/local\/lib -L. -fstack-protector -rdynamic -Wl,-export-dynamic  -L\/home\/alec\/.rvm\/gems\/ruby-2.0.0-p247\/gems\/rice-1.5.1\/ruby\/lib\/lib -lrice     -Wl,-R -Wl,\/home\/alec\/.rvm\/rubies\/ruby-2.0.0-p247\/lib -L\/home\/alec\/.rvm\/rubies\/ruby-2.0.0-p247\/lib -lruby  -lpthread -lrt -ldl -lcrypt -lm   -lc\"\ncc1plus: warning: command line option \u2018-Wdeclaration-after-statement\u2019 is valid for C\/ObjC but not for C++ [enabled by default]\ncc1plus: warning: command line option \u2018-Wimplicit-function-declaration\u2019 is valid for C\/ObjC but not for C++ [enabled by default]\nchecked program was:\n<\/code><\/pre>\n<p>The g++ command seems to show that it&#8217;s correctly looking for the headers in \/usr\/local\/include and that it&#8217;s also correctly looking for the libraries in \/usr\/local\/lib from the flags:<\/p>\n<pre><code>-I\/usr\/local\/include\n-L\/usr\/local\/lib\n<\/code><\/pre>\n<p>but for some reason it can&#8217;t seem to find any of the libraries.<\/p>\n<p>The really odd part is that two days ago I built everything (with the same version of opencv) on a different ubuntu instance (also 12.04) and everything worked fine.<\/p>\n<p>I looked around on stackoverflow for a while and found this, which seems to be a similar problem except he&#8217;s on NetBSD and I&#8217;m running Ubuntu.<\/p>\n<p>How to get Ruby to find a native lib?<\/p>\n<p>Unfortunately it looks like nobody has confirmed a solution to his issue yet though either.<\/p>\n<p>Any help would be greatly appreciated, thanks.<\/p>\n<p>EDIT:<\/p>\n<p>Hmm, I was using ruby version 2.0.0-p247 and I just switched back to 1.9.3-p362 and now everything works fine.<\/p>\n<p>EDIT 2:<\/p>\n<p>Solved it, sort of. I had to rebuild ruby 1.9.3-p362 with the configuration option &#8211;enable-shared set. Via rvm this would be:<\/p>\n<pre><code>$ rvm install 1.9.3-p362 -C --enable-shared\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m trying to correctly link OpenCV shared libraries to a ruby c++ extension and for some reason any call to have_library() is failing for the opencv libraries. I installed opencv to \/usr\/local so the header files are all in \/usr\/local\/include and the libraries are all in \/usr\/local\/lib. I&#8217;ll attach my extconf.rb and related output below. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7342","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7342","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7342"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7342\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7342"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7342"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7342"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}