我阅读了很多相关主题(如1、2、3),但我自己没有找到答案,所以我在这里。
我有一个可以构建和执行的 CMake 项目,比如说“x”。我创建了一个名为“a.so”的共享库,它依赖于其他名为“b.so”的共享库。我想在“x”中使用“a”。
这是我简化的“x”CMakelists.txt:
SET(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
LINK_DIRECTORIES(${ROOT_DIR}/lib/a/bin/) # contains liba.so
INCLUDE_DIRECTORIES(${ROOT_DIR}/lib/a/include/) # contains "a" headers
ADD_EXECUTABLE(x ${SOURCE})
TARGET_LINK_LIBRARIES(x a)
“x”编译输出提取:
Linking CXX executable ../bin/x
/usr/bin/cmake -E cmake_link_script CMakeFiles/x.dir/link.txt --verbose=1
/usr/lib64/ccache/c++ -std=c++0x CMakeFiles/x.dir/src/main /Main.cpp.o
... -L/.../lib/a/bin -rdynamic -la -Wl,-rpath,/.../lib/a/bin
"a" 和 "b" 编译。
问题是当我想编译 x 时,链接时出现错误:未定义对“函数名”的引用。 我也尝试链接到“b”,但它仍然无法正常工作。
这里也出现了“b”,但我得到了同样的错误......
Linking CXX executable ../bin/x
/usr/bin/cmake -E cmake_link_script CMakeFiles/x.dir/link.txt --verbose=1
/usr/lib64/ccache/c++ -std=c++0x CMakeFiles/x.dir/src/main
/Main.cpp.o -o ../bin/x -L/.../lib/b/bin -L/.../lib/a/bin
-rdynamic -lb -la -Wl,-rpath,/.../lib/b/bin:/.../lib/a/bin
这是错误输出:
$ make
[ 20%] Automatic moc for target x
Linking CXX executable ../bin/x
/.../lib/b/bin/b.so: undefined reference to `snd_pcm_sw_params_set_start_threshold'
/.../lib/b/bin/b.so: undefined reference to `snd_seq_delete_simple_port'
/.../lib/b/bin/b.so: undefined reference to `snd_pcm_info_set_device'
/.../lib/b/bin/b.so: undefined reference to `snd_pcm_sw_params'
/.../lib/b/bin/b.so: undefined reference to `snd_pcm_sw_params_set_silence_threshold'
/.../lib/b/bin/b.so: undefined reference to `snd_pcm_hw_params_any'
/.../lib/b/bin/b.so: undefined reference to `snd_seq_drain_output'
/.../lib/b/bin/b.so: undefined reference to `snd_ctl_pcm_next_device'
...
collect2: error: ld returned 1 exit status
CMakeFiles/x.dir/build.make:163: recipe for target '../bin/x' failed
make[2]: *** [../bin/x] Error 1
CMakeFiles/Makefile2:60: recipe for target 'CMakeFiles/x.dir/all' failed
make[1]: *** [CMakeFiles/x.dir/all] Error 2
Makefile:76: recipe for target 'all' failed
make: *** [all] Error 2
我看不出有什么问题,现在我很困惑,因为我尝试了很多事情来让事情正常工作......但没有任何工作。
任何想法?
谢谢!