[英]CMAKE shared library only creates the DLL and not the associated LIB
I am using CMAKE for configuring my project for Visual Studio and I have the following setup: 我正在使用CMAKE为Visual Studio配置项目,并且具有以下设置:
PROJECT(Proj1)
CMAKE_MINIMUM_REQUIRED(VERSION 3.2.0)
# RPATH stuff - to avoid losing linking information
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# Variable for header and source files
SET(HEADERS
api/mylib.h
)
SET(SOURCES
api/mylib.cpp
)
# Compile and link
ADD_LIBRARY(${NAME} SHARED ${HEADERS} ${SOURCES})
TARGET_LINK_LIBRARIES(${NAME} ${LIBS})
Now, this creates the project and I can compile it but it only produces the Proj1.dll
file and not the associatwed lib
file. 现在,这将创建项目,并且我可以对其进行编译,但是它仅生成
Proj1.dll
文件,而不生成相关的lib
文件。 I thought both the library and the shared object file should have been produced. 我认为库和共享库文件都应该已经生成。
I am using CMAKE 3.11.0
and Visual Studio Community 2017
我正在使用
CMAKE 3.11.0
和Visual Studio Community 2017
To create static library .lib, you have to use STATIC keyword instead of SHARED 要创建静态库.lib,您必须使用STATIC关键字而不是SHARED
ADD_LIBRARY(${NAME} STATIC ${HEADERS} ${SOURCES})
Take a look at: https://cmake.org/cmake/help/v3.0/command/add_library.html 看一下: https : //cmake.org/cmake/help/v3.0/command/add_library.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.