2

我正在尝试将 OpenCV 共享库正确链接到 ruby​​ c++ 扩展,并且由于某种原因,对 opencv 库的 have_library() 的任何调用都失败了。我将opencv安装到/usr/local,所以头文件都在/usr/local/include中,库都在/usr/local/lib中。我将在下面附上我的 extconf.rb 和相关输出。

require "mkmf-rice"

dir_config("opencv_core", "/usr/local/include", "/usr/local/lib")
unless have_library("opencv_core")
    raise "Could not find opencv_core"
end

dir_config("opencv_flann", "/usr/local/include", "/usr/local/lib")
unless have_library("opencv_flann")
    raise "Could not find opencv_flann"
end

dir_config("opencv_highgui", "/usr/local/include", "/usr/local/lib")
unless have_library("opencv_highgui")
    raise "Could not find opencv_highgui"
end

dir_config("opencv_features2d", "/usr/local/include", "/usr/local/lib")
unless have_library("opencv_features2d")
    raise "Could not find opencv_features2d"
end

dir_config("opencv_nonfree", "/usr/local/include", "/usr/local/lib")
unless have_library("opencv_nonfree")
    raise "Could not find opencv_nonfree"
end

dir_config("opencv_objdetect", "/usr/local/include", "/usr/local/lib")
unless have_library("opencv_objdetect")
    raise "Could not find opencv_objdetect"
end

create_makefile("something")

运行 $ ruby​​ extconf.rb 输出以下错误,表示找不到 opencv_core 的共享库。我还自己尝试了其他库,但它们也都失败了。

checking for main() in -lopencv_core... no
*** 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/alec/.rvm/rubies/ruby-2.0.0-p247/bin/ruby
    --with-libpath
    --without-libpath
    --with-opencv_core-dir
    --without-opencv_core-dir
    --with-opencv_core-include
    --without-opencv_core-include=${opencv_core-dir}/include
    --with-opencv_core-lib
    --without-opencv_core-lib=${opencv_core-dir}/
    --with-opencv_corelib
    --without-opencv_corelib
extconf.rb:7:in `<main>': Could not find opencv_core (RuntimeError)

mkmf.log 开头包含以下内容:

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.
have_library: checking for main() in -lopencv_core... -------------------- no

/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.
/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.
/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.
"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"
cc1plus: warning: command line option ‘-Wdeclaration-after-statement’ is valid for C/ObjC but not for C++ [enabled by default]
cc1plus: warning: command line option ‘-Wimplicit-function-declaration’ is valid for C/ObjC but not for C++ [enabled by default]
checked program was:

g++ 命令似乎表明它正在正确地查找 /usr/local/include 中的标头,并且它也正确地从标志中查找 /usr/local/lib 中的库:

-I/usr/local/include
-L/usr/local/lib

但由于某种原因,它似乎找不到任何库。

真正奇怪的是,两天前我在一个不同的 ubuntu 实例(也是 12.04)上构建了所​​有东西(使用相同版本的 opencv)并且一切正常。

我在stackoverflow上看了一会儿,发现了这个,这似乎是一个类似的问题,除了他在NetBSD上并且我正在运行Ubuntu。

如何让 Ruby 找到原生库?

不幸的是,似乎没有人确认他的问题的解决方案。

任何帮助将不胜感激,谢谢。


编辑:

嗯,我使用的是 ruby​​ 版本 2.0.0-p247,我刚刚切换回 1.9.3-p362,现在一切正常。


编辑2:

解决了,有点。我必须使用配置选项 --enable-shared 集重建 ruby​​ 1.9.3-p362。通过 rvm 这将是:

$ rvm install 1.9.3-p362 -C --enable-shared
4

0 回答 0