CMakeLists.txt文件写法(6):要求CMake根据指定的源文件生成库文件

本文介绍了如何使用 CMake 的 ADD_LIBRARY 命令来添加一个库目标到项目中,并指定了源文件。可以根据需要设置库类型为 SHARED、STATIC 或 MODULE,默认情况下为 BUILD_SHARED_LIBS 的当前值,若未设置则默认为 STATIC。此外,还可以通过 EXCLUDE_FROM_ALL 选项控制该目标是否默认被构建。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ADD_LIBRARY: Add a library to the project using the specified source files.

  •   ADD_LIBRARY(libname [SHARED | STATIC | MODULE] [EXCLUDE_FROM_ALL]
    source1 source2 ... sourceN)

    Adds a library target. SHARED, STATIC or MODULE keywords are used to set the library type. If the keyword MODULE appears, the library type is set to MH_BUNDLE on systems which use dyld. On systems without dyld, MODULE is treated like SHARED. If no keywords appear as the second argument, the type defaults to the current value of BUILD_SHARED_LIBS. If this variable is not set, the type defaults to STATIC.

    If EXCLUDE_FROM_ALL is given the target will not be built by default. It will be built only if the user explicitly builds the target or another target that requires the target depends on it.

     

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值