So I try to link an executable to my library, which is a shared library. But CMake (target_link_libraries) tries to link to a static library.
My folder structure looks like this:
sage/
|-CMakeLists.txt
|-src/
|-include/
|-tests/
|-CMakeLists.txt
|-sandbox/
|-CMakeLists.txt
|-src/
The library is called "sage". I have a "tests" directory for projects to test the library. This is the CMakeLists.txt for the library:
cmake_minimum_required(VERSION 3.13)
project(sage VERSION 0.1.0)
set(SAGE_SOURCE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/")
file(GLOB_RECURSE SAGE_SOURCE_FILES "${SAGE_SOURCE_DIRECTORY}/*.cpp")
add_library(sage SHARED ${SAGE_SOURCE_FILES})
target_include_directories(sage PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/tests")
This is the CMakeLists.txt in test/
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/sandbox")
And this is the one in test/sandbox/
set(SANDBOX_SOURCE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/")
file(GLOB_RECURSE SANDBOX_SOURCE_FILES "${SANDBOX_SOURCE_DIRECTORY}/*.cpp")
add_executable(sandbox ${SANDBOX_SOURCE_FILES})
target_link_libraries(sandbox PRIVATE sage)
When I use "cmake --build .", I get the error that "sandbox" can not be linked to "sage.lib", because it is not found.
LINK : fatal error LNK1181: Input file "..\..\Release\sage.lib" can not be opened. [C:\Users\Daniel\Documents\Entwicklung\Cpp\sage\build\tests\sandbox\sandbox
.vcxproj]
But I defined the "sage" target to be a shared library, thus it should link to "sage.dll". I am on Windows unsing the Visual Studio 2019 compiler.