cmake add_library,然后安装库目标 [英] cmake add_library, followed by install library destination
问题描述
我正在尝试运行cmake生成makefile。在最小的工作示例中,我有3个文件和1个构建目录。
I am trying to run cmake to generate makefiles. In the minimum working example, I have three files and 1 build directory.
文件1是CMakeLists.txt,确切包含:
File 1 is CMakeLists.txt, containing exactly:
add_library (MathFunctions SHARED mysqrt.cxx)
install (TARGETS MathFunctions LIBRARY DESTINATION lib)
文件2是MathFunctions.h,其中包含函数原型,函数与mysqrt.cxx相关。
File 2 is MathFunctions.h containing the function prototype, function relates to mysqrt.cxx.
文件3是mysqrt .cxx包含include语句和函数定义。
File 3 is mysqrt.cxx containing include statement and a function definition.
当我创建一个构建子目录并运行 cmake ..时,我得到了
When I create a build sub-directory and run "cmake ..", I am getting
CMake Error at CMakeLists.txt:2 (install):
install Library TARGETS given no DESTINATION!
我的add_library不是,然后安装语句语法正确吗?如果我同时删除SHARED和LIBRARY,则cmake构建不会出错。
Isn't my add_library, then install statement grammar correct? If I remove both SHARED and LIBRARY, cmake builds without errors.
感谢您的帮助。
推荐答案
问题可能出在您在CMake所谓的 DLL平台上运行此问题以及CMake如何在此类平台上对共享库进行分类。
The problem is likely down to you running this on what CMake calls a "DLL platform" and how CMake classifies a shared library on such a platform.
从文档中获取 安装
:
From the docs for install
:
对于DLL平台,共享库的DLL部分被视为
RUNTIME
目标和相应的导入库被视为ARCHIVE
目标。所有基于Windows的系统,包括Cygwin都是DLL平台。
For DLL platforms the DLL part of a shared library is treated as a
RUNTIME
target and the corresponding import library is treated as anARCHIVE
target. All Windows-based systems including Cygwin are DLL platforms.
因此,请尝试将命令更改为:
So, try changing your command to something like:
install (TARGETS MathFunctions
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
这篇关于cmake add_library,然后安装库目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!