GTest Based Test Binary Fails at Build

642 views Asked by At

I am gonna integrate GoogleTest into my project but am facing the some troubles to make my test binary built.

As my code to test is C++20 I need to use g++-10 to build it.

In my root CMakeLists.txt I have the following definition:

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

Within the test/ subdirectory there is CMakeLists.txt file containing:

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
)

And the content of my test_sample.cpp is just:

#include <gtest/gtest.h>

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

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

    return RUN_ALL_TESTS();
}

Once I try to make it built (CMake configuration succeeds), there is the following error, related to g++-10 somehow:

[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

Does anyone have an idea, at least, what might be wrong? Something with my toolchain? libc?

Thanks to anyone willing to help or push me the right direction! Martin

0

There are 0 answers