New Discussion

Notifications

You’re not receiving notifications from this thread.

Installing ruby_opencv gem results in cannot find opencv_contrib error

11
Gems / Libraries

I am trying to install the ruby_opencv gem but it can't find opencv_contrib. I used the command 'gem install ruby-opencv -- --with-opencv-dir=/mnt/c/Users/wjones/sites/musclesound-rails/opencv/my_build_dir' which is where is loaded opencv. I have done some google searches but I can't find anything that helps. I am using Ruby 2.5.3 and Rails 5.2.4.3. The mkmf.log contains the following,

have_library: checking for -lopencv_contrib... -------------------- no

"gcc -o conftest -I/home/wjones/.rbenv/versions/2.5.3/include/ruby-2.5.0/x86_64-linux -I/home/wjones/.rbenv/versions/2.5.3/include/ruby-2.5.0/ruby/backward -I/home/wjones/.rbenv/versions/2.5.3/include/ruby-2.5.0 -I. -I/usr/include -I/mnt/c/Users/wjones/sites/musclesound-rails/opencv/my_build_dir/include -I/home/wjones/.rbenv/versions/2.5.3/include -O3 -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wmisleading-indentation -Wno-packed-bitfield-compat -Wsuggest-attribute=noreturn -Wsuggest-attribute=format -Wimplicit-fallthrough=0 -Wduplicated-cond -Wrestrict -fPIC conftest.c -L. -L/home/wjones/.rbenv/versions/2.5.3/lib -Wl,-rpath,/home/wjones/.rbenv/versions/2.5.3/lib -L/usr/lib -Wl,-rpath,/usr/lib -L/mnt/c/Users/wjones/sites/musclesound-rails/opencv/my_build_dir/lib -Wl,-rpath,/mnt/c/Users/wjones/sites/musclesound-rails/opencv/my_build_dir/lib -L. -L/home/wjones/.rbenv/versions/2.5.3/lib -fstack-protector -rdynamic -Wl,-export-dynamic -lopencv_calib3d -lstdc++ -Wl,-rpath,/home/wjones/.rbenv/versions/2.5.3/lib -L/home/wjones/.rbenv/versions/2.5.3/lib -lruby -lopencv_contrib -lopencv_calib3d -lstdc++ -lpthread -ldl -lcrypt -lm -lc"
/usr/bin/ld: cannot find -lopencv_contrib
collect2: error: ld returned 1 exit status
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: printf("%p", &t);
9: }
10:
11: return 0;
12: }
13:
14: int t(void) { ; return 0; }
/
end */


The output from the install is as follows,

wjones@WJONES-LT:/mnt/c/Users/wjones/sites/musclesound-rails$ gem install ruby-opencv -- --with-opencv-dir=/mnt/c/Users/wjones/sites/musclesound-rails/opencv/my_build_dir
Building native extensions with: '--with-opencv-dir=/mnt/c/Users/wjones/sites/musclesound-rails/opencv/my_build_dir'
This could take a while...
/home/wjones/.rbenv/versions/2.5.3/lib/ruby/2.5.0/rubygems/ext/builder.rb:76: warning: Insecure world writable dir /mnt/c in PATH, mode 040777
ERROR: Error installing ruby-opencv:
ERROR: Failed to build gem native extension.

current directory: /home/wjones/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/ruby-opencv-0.0.18/ext/opencv

/home/wjones/.rbenv/versions/2.5.3/bin/ruby -r ./siteconf20210831-1654-prpzjm.rb extconf.rb --with-opencv-dir=/mnt/c/Users/wjones/sites/musclesound-rails/opencv/my_build_dir

Check the required libraries...
checking for -lstdc++... yes
checking for -lopencv_calib3d... yes
checking for -lopencv_contrib... no
*** extconf.rb failed ***

Any help you could give would be great.

@hills of steel
To resolve the error with the ruby-opencv gem installation, ensure that you have both OpenCV and the opencv_contrib module properly installed. Verify that the contrib module is included when you build OpenCV by specifying the -D OPENCV_EXTRA_MODULES_PATH during the configuration. Make sure the paths to OpenCV are correctly passed using --with-opencv-dir, and check that libopencv_contrib is in the correct directory. Additionally, ensure the linker can find the OpenCV libraries by setting the LD_LIBRARY_PATH. If OpenCV was not built with the contrib modules, rebuild it with the correct configuration.

Did you ever get anywhere with this?

Unfortunately, no.

I'm stuck too...

  • I've run brew install opencv to install opencv 4
  • I then tried to install the gem supplying the relevant paths from homebrew: gem install ruby-opencv -- --with-opencv-lib=/opt/homebrew/Cellar/opencv/4.10.0_15/lib --with-opencv-include=/opt/homebrew/Cellar/opencv/4.10.0_15/include but I get the same error mentioned above
  • If I tell it to skip the missing "contrib" folder by adding --without-opencv_contriblib to the end, it skips that check and fails on the next one 🤷‍♂️

    Check the required libraries...
    checking for -lstdc++... yes
    checking for -lopencv_calib3d... yes
    checking for -lfalse... no
    *** extconf.rb failed ***

lo, are we all stuck at this point?

Hey, I ran into the same opencv_contrib error installing ruby_opencv. Found that ensuring opencv_contrib is correctly installed before the gem helps. Also, check your pkg-config path! If you're bored while installing, give Wordle Unlimited a try. It helped me pass the time. Hope this helps someone!

Ever struggle with gem installations failing due to cryptic errors? I sure have! I recently battled a similar issue with a Ruby gem, traced it back to a missing system dependency after hours of debugging.

@Tojima Tanzaburo Wants To Be A Masked Rider

thanks for your guide

Okay, this sounds like a tricky OpenCV linking issue! I've wrestled with similar problems before. Have you double-checked that opencv_contrib is actually in your build directory and that the path is correct? Sometimes a fresh pair of eyes helps.

Hey! I've wrestled with opencv installs before. Looking at your error, it seems like the linker isn't finding libopencv_contrib. Double-check that the opencv_contrib modules were actually built and installed in your my_build_dir. Sometimes, it's a path issue, and the linker just isn't looking in the right place. It reminds me of navigating tricky slopes in Snow Rider 3D – gotta make sure you're headed in the right direction! You could also try explicitly adding the path to your linker flags during the gem install. Hope that helps!

Experiencing that Ruby error too? I had a similar issue with another gem; it turned out to be a permissions problem. Running the install command with sudo usually fixes it for me, though I'd double-check folder permissions first.

Join the discussion
Create an account Log in