CMake building Shared library error but Static is fine

Viewed 36

I am trying to build the library, a SHARED library, with following CMakeLists.txt This is a simple learning example: https://github.com/petrasvestartas/CMAKE/tree/main/libraries

If I change the SHARED keyword to STATIC all works fine, but SHARED gives me a linking error.

What is causing this error, and how can I build those two command line projects that links a dynamic library?

LINK : fatal error LNK1104: cannot open file 'Debug\math_lib.lib' [C:\IBOIS57\_Code\Software\CPP\CMAKE\libraries\build\my_exe.vcxproj]

CMakeLists:

cmake_minimum_required(VERSION 3.0)
project(myproject LANGUAGES CXX)

# library name, library type STATIC / SHARED, and source files
add_library(math_lib SHARED math.cpp)

# you do not need to specify math.cpp files anymore, since they are in math_lib
add_executable(my_exe main.cpp)
add_executable(my_exe_2 main_2.cpp)

# link executables to the library, with a PUBLIC / PRIVATE / INTERFACE keyword
# there can be more than one library e.g. target_link_libraries(my_exe PUBLIC math_lib other_library_1 other_library_2)
target_link_libraries(my_exe PUBLIC math_lib)
target_link_libraries(my_exe_2 PUBLIC math_lib)

enter image description here

0 Answers
Related