Home > OS >  How to stop cmake from trying to link against non-existing library?
How to stop cmake from trying to link against non-existing library?

Time:03-09

I am sorry if this is a naive question, as I'm quite unfamiliar with CMake in general.

I am trying to compile a very large open-source software project (OpenCV). I seem to have get most libraries that is needed into the path using the following command line arguments.

-DCUDNN_INCLUDE_DIR='${CONDA_PREFIX}/include' \
-DCUDNN_LIBRARY='/${CONDA_PREFIX}/lib' \
-DC_INCLUDE_PATH=${CONDA_PREFIX}/include:/usr/local/include:/usr/include/x86_64-linux-gnu: \
-DINCLUDE_PATH=${CONDA_PREFIX}/include:/usr/local/include:/usr/include/x86_64-linux-gnu \
-DC_PATH=${CONDA_PREFIX}/include:/usr/local/include:/usr/include/x86_64-linux-gnu \
-DLD_LIBARY_PATH=${CONDA_PREFIX}/lib:/usr/lib/x86_64-linux-gnu \

Indeed, CMake is able to find the libraries it needs, like CUDA, CuDNN, OpenBlas, FFMpeg, etc. Everything seems to go well for a while.

At the linking stage, however, CMake keeps attaching a weird library reference "-llib". lib is a non-existent library, of course. For example, one such command is

cd /home/albert/app/src/opencv/build/modules/cudev && /usr/bin/cmake -E cmake_link_script CMakeFiles/opencv_cudev.dir/link.txt --verbose=1

/usr/bin/c -fPIC -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Winit-self -Wpointer-arith -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -Wno-undef -Wno-missing-declarations -Wno-unused-function -Wno-unused-variable -Wno-enum-compare -Wno-shadow -O3 -DNDEBUG -DNDEBUG -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a -Wl,--gc-sections -Wl,--as-needed -shared -Wl,-soname,libopencv_cudev.so.4.4 -o ../../lib/libopencv_cudev.so.4.4.0 CMakeFiles/opencv_cudev.dir/src/stub.cpp.o -L/usr/local/cuda/lib64 -L/home/albert/.conda/envs/denseflow -Wl,-rpath,/usr/local/cuda/lib64:/home/albert/.conda/envs/denseflow::::::::::::::::::::::: -ldl -lm -lpthread -lrt ../../3rdparty/lib/libippiw.a ../../3rdparty/ippicv/ippicv_lnx/icv/lib/intel64/libippicv.a -lcudart_static -lpthread -ldl -lrt -lnppc -lnppial -lnppicc -lnppidei -lnppif -lnppig -lnppim -lnppist -lnppisu -lnppitc -lnpps -lcublas -llib -lcufft -L/usr/local/cuda/lib64 -L/usr/lib/x86_64-linux-gnu -L/home/albert/.conda/envs/denseflow -lcudart_static -lpthread -ldl -lrt -lnppc -lnppial -lnppicc -lnppidei -lnppif -lnppig -lnppim -lnppist -lnppisu -lnppitc -lnpps -lm -lpthread -lcublas -llib -lcufft

This causes the following error.

/usr/bin/ld: cannot find -llib collect2: error: ld returned 1 exit status make[2]: *** [modules/cudev/CMakeFiles/opencv_cudev.dir/build.make:89: lib/libopencv_cudev.so.4.4.0] Error 1

If I manually remove the "-llib" (both occurrences) from the C command, the command executes successfully.

What is happening here?

Although I'm unfamiliar with CMake, it feels like there should be a straightforward way to prevent CMake from doing this.

Thank you so much for your help.

Update: There does seem to be something wrong with the OpenCV CMake files. When I run CMake, one of its output is

-- Extra dependencies: dl m pthread rt cudart nppc nppial nppicc nppidei nppif nppig nppim nppist nppisu nppitc npps cublas lib cufft -L/usr/local/cuda-11.6/lib64 -L/home/albert/.conda/envs/denseflow

The mysterious lib already appears here.

Someone on the Internet suggests modifying CMakeCache.txt manually, but I wasn't able to get it to work. CMake just overwrites it after my modifications.

CodePudding user response:

The problem is caused by the following CMake option.

-DCUDNN_LIBRARY='/${CONDA_PREFIX}/lib'

Removing this option solved the problem. It seems that this path should be to a file, not a directory. I'm not sure which file it should point to for CUDA 11.6 and CuDNN 8.3.2, but simply removing this line is sufficient.

  • Related