Hello,
I’m building my own librairy. I try to build a static and a share version (I’m using visual studio community)
my structure:
root
|
|-algos
| |-src
| | |*.cpp
| |
| |-include
| | |*.h
| |
| | CMakeLists.txt
| CMakeLists.txt
the root cmake is
cmake_minimum_required (VERSION 3.8)
# Enable Hot Reload for MSVC compilers if supported.
if (POLICY CMP0141)
cmake_policy(SET CMP0141 NEW)
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
endif()
project ("algos")
add_subdirectory ("aglos")
and the algos/cmake
add_library(algos src/exceptions.cpp
src/localResearch.cpp
src/point.cpp
src/utils.cpp)
add_library(algos_shared SHARED src/exceptions.cpp
src/localResearch.cpp
src/point.cpp
src/utils.cpp)
add_executable(exemple1 exemple/function_optimisation.cpp)
target_link_libraries(exemple1 PRIVATE algos_shared)
The problem is i get an lnk1104: impossible to open algos_shared.lib.
why, if i give to target_link_library a shared library, cmake is looking for .lib?
If i change the last ligne by:
target_link_libraries(exemple1 PRIVATE algos)
visual studio say to me that an executable is missing for the target and “the value cant be null parameter name: key”
if i delete the section
add_library(algos_shared SHARED src/exceptions.cpp
src/localResearch.cpp
src/point.cpp
src/utils.cpp)
the exemple work perfectly.
Can someone explain me what happen here and how to build and link also shared library?
Thank you advance