我的CMakeList.txt
有以下有问题的部分:
add_executable(esh_test tests/libtest.c esh.c tests/esh_test.cpp)
add_dependencies(esh_test esh)
target_link_libraries(esh_test
${CMAKE_SOURCE_DIR}/esh-grammar.o
${CMAKE_SOURCE_DIR}/libesh.a
l dl readline curses libgtest gtest_main)
有问题,因为它无法正确链接:
$> cmake ./; make
-- Configuring done
-- Generating done
-- Build files have been written to: src/
[ 0%] Built target lexpar
[ 0%] Built target libesh
[ 14%] Built target esh
[ 71%] Built target gtest
[ 78%] Linking CXX executable esh_test
CMakeFiles/esh_test.dir/esh_test.cpp.o: In function `testcase_test_test_Test::TestBody()':
esh_test.cpp:(.text+0xe): undefined reference to `mkredir()'
esh_test.cpp:(.text+0x1c): undefined reference to `esh_usage(char*)'
esh_test.cpp:(.text+0x28): undefined reference to `redir_restore_streams(redir*)'
esh_test.cpp:(.text+0x3a): undefined reference to `fd_grep_regex(int, char*)'
esh_test.cpp:(.text+0x107): undefined reference to `redir_cleanup(redir*)'
collect2: error: ld returned 1 exit status
此模块的link.txt
为:
/usr/bin/c++ -std=c++11 CMakeFiles/esh_test.dir/esh_test.cpp.o CMakeFiles/esh_test.dir/libtest.c.o CMakeFiles/esh_test.dir/esh.c.o -o esh_test -rdynamic ../esh-grammar.o ../libesh.a -ll -ldl -lreadline -lcurses gtest/src/gtest-build/libgtest.a -lgtest_main -lpthread
它似乎会链接在libtest.h
中声明并在libtest.c
中定义的缺失函数中。
这是我的第一个CMake项目,所以我有点失落。这里发生了什么?