Sorry if this question is a bit long winded. I know there is a lot of ground already covered here.
Essentially I get the below error when including my tst_engine.lib in another target.
lld-link: error: undefined symbol: SDL_Init
>>> referenced by C:\Users\n10255460\CLionProjects\2D_engine_and_game\tst_engine\TstGameEngine.cpp:22
>>> tst_engine.lib(TstGameEngine.cpp.obj):(public: __cdecl tst::TstGameEngine::TstGameEngine(bool *))
lld-link: error: undefined symbol: SDL_Quit
>>> referenced by C:\Users\n10255460\CLionProjects\2D_engine_and_game\tst_engine\TstGameEngine.cpp:43
>>> tst_engine.lib(TstGameEngine.cpp.obj):(public: __cdecl tst::TstGameEngine::~TstGameEngine(void))
ninja: build stopped: subcommand failed.
As It says above, SDL is used in a .cpp file not a .h file. On top of this, this error goes away when including SDL as a dependency in the target I'm attempting to compile with tst_engine as a library.
As far as I've previously understood things, if a third party library is in a source file it should never become a dependency for those who use the lib associated with the source file. Below are the two relevant cmake files:
executable that triggers the error:
cmake_minimum_required(VERSION 3.24)
project(game)
set(CMAKE_CXX_STANDARD 20)
include_directories(../tst_engine)
set(lib ${CMAKE_SOURCE_DIR}\\libraries\\lib)
include_directories(${CMAKE_SOURCE_DIR}\\libraries\\include)
add_executable(game main.cpp)
target_link_libraries(game
${CMAKE_SOURCE_DIR}\\cmake-build-debug\\tst_engine\\tst_engine.lib
)
library that compiles successfully:
cmake_minimum_required(VERSION 3.24)
project(tst_engine)
set(CMAKE_CXX_STANDARD 20)
set(lib ${CMAKE_SOURCE_DIR}\\libraries\\lib)
include_directories(${CMAKE_SOURCE_DIR}\\libraries\\include)
add_library(tst_engine STATIC TstGameEngine.h TstGameEngine.cpp)
target_link_libraries(tst_engine PRIVATE ${lib}\\SDL2main.lib ${lib}\\SDL2.lib ${lib}\\SDL2-static.lib)