I’m starting to learn C++ and CMake is a bigger struggle for me.
I’ve written a little code to get me started and also wanted to write tests from the very beginning.
Except that I get Undefined Symbols every time I run my test.
I already have #include “ConfigStore.h” in test.cp and the file seems to be recongnized
Error when compiling :
[build] ld: Undefined symbols:
[build] ConfigStore::addValue(std::__1::basic_string<char, std::__1::char_traits<char>
...
[build] clang: error: linker command failed with exit code
Here’s how I made things :
Project structure
root:
CMakeLists.txt
root/Infrastructure/ConfigStore:
ConfigStore.h /ConfigStore.cpp -> (include “../Singleton/Singleton.h”)
CMakeLists.txt
root/Infrastructure/Singleton:
Singleton.h / Singleton.cpp
root/test
CMakeLists.txt
googletest
ConfigStore_test.cpp
To be concise, here’s how I managed to add ConfigStore to my test proect.
CMakeLists (TEST) :
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/googletest/include ${CMAKE_SOURCE_DIR}/Infrastructure/ConfigStore)
link_directories(${BinanceAPI_LIB_OUT}/ConfigStore)
And in CMakeLists.txt :
set(LIBRARY_OUTPUT_PATH ${BinanceAPI_LIB_OUT}/${PROJECT_NAME})
set(CONFIG_STORE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
add_library(${PROJECT_NAME} SHARED ConfigStore)```
And the root CMakeLists.txt :
```add_subdirectory(${CMAKE_SOURCE_DIR}/Infrastructure/ConfigStore)
add_subdirectory(test)
add_library(BinanceAPI BinanceAPI.cpp)
target_link_libraries(${PROJECT_NAME} PUBLIC
ConfigStore)```
I know this is a lot of code, but I'm really struggling getting what's wrong. Thanks for helping !