0

我要将 GoogleTest 集成到我的项目中,但是在构建我的测试二进制文件时遇到了一些麻烦。

由于我要测试的代码是 C++20,我需要使用 g++-10 来构建它。

在我的根 CMakeLists.txt 中,我有以下定义:

...
include( CTest )
# Find Google Test package
find_package( GTest REQUIRED )
add_subdirectory( ${CMAKE_CURRENT_SOURCE_DIR}/test )

在 test/ 子目录中有 CMakeLists.txt 文件,其中包含:

project( ReVolta-Kernel-Tests VERSION 0.1.0 LANGUAGES CXX C )

set( TEST_SAMPLE_TARGET "sample" )

add_executable( ${TEST_SAMPLE_TARGET} )

target_sources( ${TEST_SAMPLE_TARGET}
PRIVATE
    ${CMAKE_CURRENT_LIST_DIR}/test_sample.cpp
)

target_include_directories( ${TEST_SAMPLE_TARGET}
PUBLIC
    # Google Test inclusions
    ${GTEST_INCLUDE_DIRS}
)

target_link_libraries( ${TEST_SAMPLE_TARGET}
PUBLIC
    ${GTEST_LIBRARIES}
    pthread
)

而我的 test_sample.cpp 的内容只是:

#include <gtest/gtest.h>

#if true
TEST( Sample, FirstTest ) {
    
}
#endif

int main( int argc, char ** argv ) {
    testing::InitGoogleTest( &argc, argv );

    return RUN_ALL_TESTS();
}

一旦我尝试构建它(CMake配置成功),就会出现以下错误,与g++-10有关:

[build] Scanning dependencies of target test_sample.cpp
[build] [ 50%] Building CXX object test/kernel/CMakeFiles/test_sample.dir/test_sample.o
[build] In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/c++config.h:518,
[build]                  from /usr/include/c++/10/limits:42,
[build]                  from /usr/local/include/gtest/gtest.h:55,
[build]                  from /home/martin/git/revolta/test/kernel/test_sample.cpp:1:
[build] /usr/include/x86_64-linux-gnu/c++/10/bits/os_defines.h:39:10: fatal error: features.h: File or directory does not exist
[build]    39 | #include <features.h>
[build]       |          ^~~~~~~~~~~~
[build] compilation terminated.
[build] make[3]: *** [test/kernel/CMakeFiles/test_sample.dir/build.make:82: test/kernel/CMakeFiles/test_sample.dir/test_sample.o] Chyba 1
[build] make[2]: *** [CMakeFiles/Makefile2:897: test/kernel/CMakeFiles/test_sample.dir/all] Chyba 2
[build] make[1]: *** [CMakeFiles/Makefile2:904: test/kernel/CMakeFiles/test_sample.dir/rule] Chyba 2
[build] make: *** [Makefile:512: test_sample] Chyba 2

有没有人有一个想法,至少,什么可能是错的?我的工具链有什么东西吗?库?

感谢任何愿意帮助或推动我正确方向的人!马丁

4

0 回答 0