CMake安装未在Windows上安装库 [英] CMake install is not installing libraries on Windows

查看:111
本文介绍了CMake安装未在Windows上安装库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某些原因,下面的CMake文件无法安装项目库。它在正确的位置创建目录,甚至递归安装标题...但是无法安装该库。

For some reason, the below CMake file fails to install the project libraries. It creates the directory in the right location, and it even recursively installs the headers... But it fails to install the library. How can this be fixed?

cmake_minimum_required(VERSION 2.8)
project(MyLib)

include_directories(include)
add_library(MyLib SHARED source/stuff.cpp)

if(CMAKE_SYSTEM MATCHES "Windows")
target_link_libraries(MyLib DbgHelp ws2_32 iphlpapi)
set(CMAKE_INSTALL_PREFIX "../../devel_artifacts")
endif(CMAKE_SYSTEM MATCHES "Windows")

install(TARGETS MyLib LIBRARY DESTINATION "lib"
                      ARCHIVE DESTINATION "lib"
                      COMPONENT library)
install(DIRECTORY include/${PROJECT_NAME} DESTINATION include)


推荐答案

您只是在RUNTIME DESTINATION 参数。 org / cmake / help / git-master / command / install.html rel = noreferrer> install(TARGETS ...) 命令。

You're just missing the RUNTIME DESTINATION argument in the install(TARGETS...) command.

CMake将共享库视为Windows等 DLL平台上的运行时对象。如果将命令更改为:

CMake treats shared libraries as runtime objects on "DLL platforms" like Windows. If you change your command to:

install(TARGETS MyLib LIBRARY DESTINATION "lib"
                      ARCHIVE DESTINATION "lib"
                      RUNTIME DESTINATION "bin"
                      COMPONENT library)

然后您应该找到MyLib .dll最终显示在 devel_artifacts / bin中。

then you should find that MyLib.dll ends up in "devel_artifacts/bin".

这篇关于CMake安装未在Windows上安装库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆