Я получаю эту ошибку
< pre class="lang-bash Prettyprint-override">
Код: Выделить всё
$ make
Consolidate compiler generated dependencies of target spawn
[ 60%] Built target spawn
[ 80%] Building CXX object CMakeFiles/spawn_test.dir/test/UT_Spawn.cpp.o
/home/alexn/Fork_test/test/UT_Spawn.cpp:5:10: fatal error: src/spawn.h: No such file or directory
5 | #include "src/spawn.h"
| ^~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/spawn_test.dir/build.make:76: CMakeFiles/spawn_test.dir/test/UT_Spawn.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:111: CMakeFiles/spawn_test.dir/all] Error 2
make: *** [Makefile:101: all] Error 2
Код: Выделить всё
$ tree -L 2
.
├── CMakeLists.txt
├── main.cpp
├── src
│ ├── spawn.cpp
│ └── spawn.h
└── test
└── UT_Spawn.cpp
Код: Выделить всё
/* Basic include */
#include
/* Include soruce file */
#include "src/spawn.h"
TEST(SpawnTest, JustTest) {
EXPECT_DEATH(FORK::spawn_pid(true), "");
}
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Код: Выделить всё
cmake_minimum_required(VERSION 3.22)
project(gtest_mock)
set(CMAKE_CXX_STANDARD 14)
# Adding source file
file(
GLOB_RECURSE
SOURCE_FILES
"src/*.cpp"
main.cpp)
add_executable(spawn ${SOURCE_FILES})
# Adding Gtest
enable_testing()
include(GoogleTest)
file(
GLOB_RECURSE
TEST_FILES
"test/*.cpp")
add_executable(spawn_test ${TEST_FILES})
target_include_directories(spawn_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_link_libraries(
spawn_test
gtest
gtest_main
pthread)
gtest_discover_tests(spawn_test)
Код: Выделить всё
/usr/bin/ld: CMakeFiles/spawn_test.dir/test/UT_Spawn.cpp.o: in function `SpawnTest_JustTest_Test::TestBody()':
UT_Spawn.cpp:(.text+0x13a): undefined reference to `FORK::spawn_pid(bool)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/spawn_test.dir/build.make:97: spawn_test] Error 1
make[1]: *** [CMakeFiles/Makefile2:111: CMakeFiles/spawn_test.dir/all] Error 2
make: *** [Makefile:101: all] Error 2
Подробнее здесь: https://stackoverflow.com/questions/791 ... or-directo