Search code examples
macosopencvmacos-high-sierra

Linking error while compiling opencv with cuda on high sierra


I am getting a linking error while compiling opencv with cuda on Mac OS X high Sierra (10.13.6).

Error message:

[ 21%] Linking CXX shared library ../../lib/libopencv_cudev.dylib
ld: warning: directory not found for option '-L/Users/unknownn/opencv/-Wl,-rpath,/usr/local/cuda'
ld: warning: directory not found for option '-L-Wl,-rpath,/usr/local/cuda'
ld: library not found for -llib
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [lib/libopencv_cudev.4.0.1.dylib] Error 1
make[1]: *** [modules/cudev/CMakeFiles/opencv_cudev.dir/all] Error 2
make: *** [all] Error 2

I have already tried pretty much every cuda (9, 9.2, 10) and opencv (3.4, 4.0.1) version. Also I am aware that every cuda version requires a specific Xcode version.

I have also tried various cmake versions

I checked for the correct cuda paths in ccmake.

I dont know why the ld warnings appear since /usr/local/cuda exist.

What is -llib?


Solution

  • I had the same problem as well, what's interesting is that the problem does not appear to be with OpenCV, but with cmake.

    The FindCUDA that comes with cmake seems to be broken, producing that strange -llib. You can see it during the cmake run as well as:

    Extra dependencies:          cudart_static lib nppc nppial nppicc nppicom nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cufft -L/usr/local/cuda/lib -L-Wl,-rpath,/usr/local/cuda
    

    (Note the second element "lib", the last two -L... elements will cause problem when you do make install as well)

    However, the opencv source package comes with FindCUDA.cmake files that seem to work.

    Assuming: cmake is in /usr/local/share/cmake opencv source is in ~/opencv

    Do the following first:

    mv /usr/local/share/cmake/Modules/FindCUDA* /tmp # Or some other back up location
    cp -r ~/opencv/cmake/FindCUDA* /usr/local/share/cmake/Modules
    

    Then run your build steps as before (cmake ..., make ..., make install), and hopefully it will work this time (it did for me).

    As far as I can tell, cmake has deprecated FindCUDA.cmake, so I'm guessing it won't get fixed any time soon.