c++ - 在 LINUX 中构建 Gtest 框架
问题描述
我已经下载了 GTest 源代码 googletest-release-1.8.0.tar.gz (来自 : github )并提取了它。(在 CentOS 上工作)之后我运行了以下命令:
- cd googletest-release-1.8.0\googletest。
cmake CMakeLists.txt。输出: -- 配置完成 -- 生成完成 -- 构建文件已写入:gtestframework/googletest-release-1.8.0/googletest
制作。输出:[50%] 构建目标 gtest [100%] 构建目标 gtest_main
在此之后,我将文件 libgtest_main.a 和 libgtest.a 复制到 /usr/lib 中。
- cd googletest-release-1.8.0\googlemock\gtest。
- 将 libgtest_main.so libgtest.so libGTest.so 复制到 /usr/lib 文件夹中。
- cd gtestframework\Testcode //{Testcode中的2个C++文件}
- cmake CMakeLists.txt。
- 制作。
我收到了这个错误:
Linking CXX executable runTests
CMakeFiles/runTests.dir/tests.cpp.o: In function `__static_initialization_and_destruction_0(int, int)':
tests.cpp:(.text+0x95a): undefined reference to `testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, testing::internal::CodeLocation, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)'
tests.cpp:(.text+0xa14): undefined reference to `testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, testing::internal::CodeLocation, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)'
CMakeFiles/runTests.dir/tests.cpp.o: In function `testing::AssertionResult testing::internal::CmpHelperEQFailure<int, double>(char const*, char const*, int const&, double const&)':
tests.cpp:(.text._ZN7testing8internal18CmpHelperEQFailureIidEENS_15AssertionResultEPKcS4_RKT_RKT0_[_ZN7testing8internal18CmpHelperEQFailureIidEENS_15AssertionResultEPKcS4_RKT_RKT0_]+0x6c): undefined reference to `testing::internal::EqFailure(char const*, char const*, std::string const&, std::string const&, bool)'
CMakeFiles/runTests.dir/tests.cpp.o: In function `testing::AssertionResult testing::internal::CmpHelperEQFailure<double, double>(char const*, char const*, double const&, double const&)':
tests.cpp:(.text._ZN7testing8internal18CmpHelperEQFailureIddEENS_15AssertionResultEPKcS4_RKT_RKT0_[_ZN7testing8internal18CmpHelperEQFailureIddEENS_15AssertionResultEPKcS4_RKT_RKT0_]+0x6c): undefined reference to `testing::internal::EqFailure(char const*, char const*, std::string const&, std::string const&, bool)'
collect2: error: ld returned 1 exit status
make[2]: *** [runTests] Error 1
make[1]: *** [CMakeFiles/runTests.dir/all] Error 2
make: *** [all] Error 2
CMakeLists.txt 文件内容:
cmake_minimum_required(VERSION 2.6)
# Locate GTest
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})
# Link runTests with what we want to test and the GTest and pthread library
add_executable(runTests tests.cpp)
target_link_libraries(runTests ${GTEST_LIBRARIES} pthread)
解决方案
推荐阅读
- python - 在 Windows 上安装 tensorflow 的问题
- c# - 如何在循环中更改颜色和清除标签?
- multicore - 使用尖峰模拟器的 RISC-V 多核应用
- reactjs - 是否可以在 React 中使用“无限滚动”?
- javascript - 添加新数据时如何将 prev.data 保存在 localStorage 中?
- android - 有没有办法在 Android 和 Bluefy(iOS 浏览器)中阻止 Google Analytics 跟踪
- oracle - sqldeveloper连接时引用的字符串未正确终止错误
- python - 一段时间后Python终止子进程
- laravel - Laravel 政策问题
- docker - Docker:如何在构建 dockerfile 时链接外部文件夹