I'm trying to link my project with google C++ testing framework. I have this directory structure:
-- GeKon --- gekon (where my project is)
|-- tests -- lib (google test)
The project structure is supposed to replicate this example from creators of CLion: Calendar
CMakeFiles have this content:
root CMakeFile
cmake_minimum_required (VERSION 2.8)
project(Gekon)
include_directories(gekon)
add_subdirectory(gekon)
add_subdirectory(tests)
gekon CMakeFile (Few lines were omitted to make it shorter)
project (gekon)
find_package(OpenCV REQUIRED)
set(HEADER_FILES ...)
set(SOURCE_FILES gk_functions.cpp)
add_executable(gekon_run main.cpp ${SOURCE_FILES} ${HEADER_FILES})
target_link_libraries(gekon_run ${OpenCV_LIBS})
add_library(gekon STATIC ${SOURCE_FILES} ${HEADER_FILES})
tests CMakeFile
project(gekon_tests)
add_subdirectory(lib)
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
find_package(OpenCV REQUIRED)
add_executable(runGekonTests first_test.cpp)
target_link_libraries(runGekonTests gtest gtest_main)
target_link_libraries(runGekonTests gekon)
target_link_libraries(runGekonTests ${OpenCV_LIBS})
But I'm still getting an error from linker, that it cannot find reference to the function:
CMakeFiles/runGekonTests.dir/first_test.cpp.o: In function `fitness_mse_test_test_equal_Test::TestBody()':
/path/tests/first_test.cpp:32:undefined reference to `gekon::fitness_mse(gekon::tr_sample_t, cv::Mat)'
collect2: error: ld returned 1 exit status
tests/CMakeFiles/runGekonTests.dir/build.make:135: recipe for target 'tests/runGekonTests' failed
gmake[3]: *** [tests/runGekonTests] Error 1
I've also tried few suggestions from StackOwerflow like this one: How do I tell CMake to link in a static library in the source directory? but still no success.
What should I do to make it work?
The project source code is here:
cmake version 3.4.1
gcc version 5.3.1
Solution
The problem was neither in the cmakefile nor in tests. My *.cpp file was wrong. Instead of namespace gekon {...}
I was using using namespace gekon
.