我正在使用CMake 3.19
我正在编译一个C应用程序,该应用程序在
${PROJECT_SOURCE_DIRECTORY}/lib
文件夹
以下是我的CMakeLists.txt的相关片段:
target_link_directories(TargetApp PUBLIC "/usr/local/lib"
${PROJECT_SOURCE_DIRECTORY}/lib )
get_target_property(OUT TargetApp LINK_DIRECTORIES)
#message("directories:" ${OUT})
target_link_libraries(TargetApp
"m"
"coolfoo"
)
get_target_property(OUT TargetApp LINK_LIBRARIES)
#message("linked libs:" ${OUT})
控制台上的消息显示链接路径是正确的,并且正确添加了正确的库。
最后,但同样重要的是,我使用
ldd
以检查第三方库中是否有任何丢失的符号(没有丢失的符号)。
这是
ldd
输出
ldd ../lib/coolfoo.so
linux-vdso.so.1 (0x00007ffd63d5f000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f81966c5000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f81964d3000)
/lib64/ld-linux-x86-64.so.2 (0x00007f81969ac000)
当我在CMake Makefile上运行make时,我得到以下错误(在链接阶段):
[ 16%] Linking C executable TargetApp
/usr/bin/ld: cannot find -lcoolfoo
collect2: error: ld returned 1 exit status
为什么
ld
找不到我的共享库?我该如何解决这个问题?
编辑
的输出
make V=1
[Fri, 08Oct21 12:49 minime@yourbox]:build$ make V=1
/home/minime/.local/bin/cmake -S/path/to/proj -B/path/to/proj/build --check-build-system CMakeFiles/Makefile.cmake 0
/home/minime/.local/bin/cmake -E cmake_progress_start /path/to/proj/build/CMakeFiles /path/to/proj/build//CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/path/to/proj/build'
make -f CMakeFiles/TargetApp.dir/build.make CMakeFiles/TargetApp.dir/depend
make[2]: Entering directory '/path/to/proj/build'
cd /path/to/proj/build && /home/minime/.local/bin/cmake -E cmake_depends "Unix Makefiles" /path/to/proj /path/to/proj /path/to/proj/build /path/to/proj/build /path/to/proj/build/CMakeFiles/TargetApp.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/path/to/proj/build'
make -f CMakeFiles/TargetApp.dir/build.make CMakeFiles/TargetApp.dir/build
make[2]: Entering directory '/path/to/proj/build'
[ 16%] Linking C executable TargetApp
/home/minime/.local/bin/cmake -E cmake_link_script CMakeFiles/TargetApp.dir/link.txt --verbose=1
/usr/bin/cc CMakeFiles/TargetApp.dir/src/server/example-server.c.o CMakeFiles/TargetApp.dir/src/server/dirlookup.pb-c.c.o CMakeFiles/TargetApp.dir/src/server/query.pb-c.c.o -o TargetApp -L/usr/local/lib -L/path/to/proj/lib -Wl,-rpath,/usr/local/lib:/path/to/proj/lib -lm -lprotobuf-c -lprotobuf-c-rpc -lcoolfoo
/usr/bin/ld: cannot find -lcoolfoo
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/TargetApp.dir/build.make:151: TargetApp] Error 1
make[2]: Leaving directory '/path/to/proj/build'
make[1]: *** [CMakeFiles/Makefile2:95: CMakeFiles/TargetApp.dir/all] Error 2
make[1]: Leaving directory '/path/to/proj/build'
make: *** [Makefile:103: all] Error 2