我正尝试在单元测试中使用GMock。但是链接失败,并出现下一个错误:
In function `testing::internal::linked_ptr_internal::depart()':
/home/user/googletest/googletest/include/gtest/internal/gtest-linked_ptr.h:127: undefined reference to `testing::internal::g_linked_ptr_mutex'
In function `testing::internal::linked_ptr_internal::join(testing::internal::linked_ptr_internal const*)':
/home/user/googletest/googletest/include/gtest/internal/gtest-linked_ptr.h:110: undefined reference to `testing::internal::g_linked_ptr_mutex'
clang: error: linker command failed with exit code 1 (use -v to see invocation)我的Cmake文件:
target_link_libraries(Test
${Boost_LIBRARIES}
${GTEST_LIBRARIES}
log4cplus
gtest
gtest_main
pthread
"-L/usr/local/lib/libgmock.a" gmock
"-L/usr/local/lib/libgmock_main.a" gmock_main
# gmock
# gmock_main
proto
$<TARGET_OBJECTS:logging_dev>)我尝试使用gmock和gmock_main,并给出了硬编码路径。所有其他仅使用GTest的测试都会成功编译和运行。
我做错了什么?:)
发布于 2020-12-22 00:02:34
首先,您必须通过以下方式查找gtest
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS}/include)然后通过以下命令将gtest *.libs链接到测试可执行文件
target_link_libraries(${EXE_NAME} PUBLIC GTest::GTest GTest::Main #other libs)https://stackoverflow.com/questions/60040511
复制相似问题