BUG: STATIC library can't link a SHARED library when compiler is MSVC.
System: Windows 11 22621.963
CMake: 3.25.0-rc1
Generator: Ninja
C++ Compiler:
- MSVC: MSVC 19.34.31937.0 (C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe)
- MinGW: GNU 10.3.0 (C:/TDM-GCC-64/bin/g++.exe)
The reproducible code is available here https://github.com/traversebitree/CMake_ISSUE_-24259.
When using compiler MSVC (cl.exe), generate and configure stages are Okay. But got "LINK1181" error when build.
The core listfile is here:
add_library(add SHARED add.cpp) # This is SHARED LIB
add_library(addmul STATIC mul_and_add.cpp) # This is STATIC LIB depends on SHARED LIB
target_link_libraries(addmul PUBLIC add) # STATIC LIB links SHARED LIB
add_executable(main main.cpp)
target_link_libraries(main PRIVATE addmul)
Using compiler MinGW (g++) is OKay, but when using compiler MSVC (cl) gets into trouble.
Edited by XyKong