gpt4 book ai didi

cmake add_library,然后是安装库目标

转载 作者:行者123 更新时间:2023-12-04 06:19:10 39 4
gpt4 key购买 nike

我正在尝试运行 cmake 来生成 makefile。在最小的工作示例中,我有三个文件和 1 个构建目录。

文件 1 是 CMakeLists.txt,其中包含:

add_library (MathFunctions SHARED mysqrt.cxx)
install (TARGETS MathFunctions LIBRARY DESTINATION lib)

文件2是包含函数原型(prototype)的MathFunctions.h,函数与mysqrt.cxx有关。

文件 3 是 mysqrt.cxx,包含包含语句和函数定义。

当我创建一个构建子目录并运行“cmake ..”时,我得到了
CMake Error at CMakeLists.txt:2 (install):
install Library TARGETS given no DESTINATION!

我的 add_library,then install 语句语法不正确吗?如果我同时删除 SHARED 和 LIBRARY,则 cmake 构建不会出错。

谢谢你的帮助。

最佳答案

问题可能在于您在 CMake 所谓的“DLL 平台”上运行它,以及 CMake 如何在这样的平台上对共享库进行分类。

来自 install 的文档:

For DLL platforms the DLL part of a shared library is treated as a RUNTIME target and the corresponding import library is treated as an ARCHIVE target. All Windows-based systems including Cygwin are DLL platforms.



因此,尝试将您的命令更改为:
install (TARGETS MathFunctions
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)

关于cmake add_library,然后是安装库目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22278381/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com