如何阻止 cmake 尝试链接不存在的库?
如果这是一个天真的问题,我很抱歉,因为我一般对 CMake 相当不熟悉。
我正在尝试编译一个非常大的开源软件项目(OpenCV)。我似乎已经使用以下命令行参数获取了路径所需的大多数库。
-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 \
事实上,CMake 能够找到它需要的库,例如 CUDA、CuDNN、OpenBlas、FFMpeg 等。一段时间内一切似乎都很顺利。
然而,在链接阶段,CMake 不断附加一个奇怪的库引用“-llib”。当然,lib 是一个不存在的库。例如,一个这样的命令是
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=返回类型 -Werror=非虚拟数据源 -Werror=地址 -Werror=序列点 -Wformat -Werror=格式安全 -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 -缺少声明 -Wno-未使用的函数 -Wno-未使用的变量 -Wno-enum-比较 -Wno-shadow -O3 -DNDEBUG -DNDEBUG -Wl,--排除库,libippicv.a -Wl,--排除库,libippiw.a -Wl,--gc-sections -Wl,--按需-共享-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
这会导致以下错误。
/usr/bin/ld: 找不到 -llib collect2:错误:ld 返回 1 退出状态 make[2]: *** [modules/cudev/CMakeFiles/opencv_cudev.dir/build.make:89: lib/libopencv_cudev.so.4.4.0] 错误 1
如果我手动删除“-llib”(两次出现)从C++命令来看,命令执行成功。
这里发生了什么?
虽然我对 CMake 不熟悉,但感觉应该有一个简单的方法来阻止 CMake 这样做。
非常感谢您的帮助。
更新: OpenCV CMake 文件似乎确实有问题。当我运行 CMake 时,其输出之一是
-- 额外依赖项:dl m pthread rt cudart nppc nppial nppicc nppidei nppif nppig nppim nppist nppisu nppitc npps cublas lib 袖口-L/usr/local/cuda-11.6/lib64 -L/home/albert/.conda/envs/denseflow
神秘的库已经出现在这里。
互联网上有人建议手动修改 CMakeCache.txt,但我无法让它工作。 CMake 在我修改后只是覆盖它。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该问题是由以下 CMake 选项引起的。
删除这个选项解决了这个问题。看来这个路径应该是一个文件,而不是一个目录。我不确定 CUDA 11.6 和 CuDNN 8.3.2 应该指向哪个文件,但只需删除这一行就足够了。
The problem is caused by the following CMake option.
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.
它应该指向 cudnn lib 文件。在 Mac 上使用这个
it should point to cudnn lib file. on Mac use this