CMakeLists:
if (MSVC)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()
add_library(${PROJECT_NAME} SHARED ${SOURCES})
CMake 2.8.12 + MSVC 2015
配置输出:
-- The C compiler identification is MSVC 19.0.24210.0
-- The CXX compiler identification is MSVC 19.0.24210.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMAKE_C_FLAGS_DEBUG is /D_DEBUG /MDd /Zi /Ob0 /Od /RTC1
CMAKE_C_FLAGS_RELEASE is /MD /O2 /Ob2 /D NDEBUG
CMAKE_C_FLAGS_RELWITHDEBINFO is /MD /Zi /O2 /Ob1 /D NDEBUG
CMAKE_C_FLAGS_MINSIZEREL is /MD /O1 /Ob1 /D NDEBUG
-- Configuring done
-- Generating done
提到https://cmake.org/pipermail/cmake/2009-March/027990.html。
您很可能没有设置类和/或函数调用 出口。如果没有导出的类/函数,Visual Studio将不会 为您生成一个导入库。
但添加CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON
会得到相同的结果。
如何使MSVC生成lib& dll喜欢mingw?
答案 0 :(得分:0)
更新cmake
2.8到3.4解决了问题。
https://cmake.org/cmake/help/v3.4/release/3.4.html?highlight=windows_export_all_symbols