cmake include_directories分析

本文详细解析了在自动化编译过程中遇到的问题,并通过官方文档深入理解include_directories函数的作用,提供了解决方案和最佳实践,帮助开发者有效管理包含目录,避免编译错误。

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

自动化编译这几天快把我折磨透了,好烦,但是还要加班来搞,现在静下来慢慢分析:

看官方文档解释:

  • include_directories: 编译时加到包含目录
  •   include_directories([AFTER|BEFORE] [SYSTEM] dir1 dir2 ...)
    

    Add the given directories to those the compiler uses to search for include files. These directories are added to the directory property INCLUDE_DIRECTORIES for the current CMakeLists file. They are also added to the target property INCLUDE_DIRECTORIES for each target in the current CMakeLists file. The target property values are the ones used by the generators.

    By default the directories are appended onto the current list of directories. This default behavior can be changed by setting CMAKE_INCLUDE_DIRECTORIES_BEFORE to ON. By using AFTER or BEFORE explicitly, you can select between appending and prepending, independent of the default. If the SYSTEM option is given, the compiler will be told the directories are meant as system include directories on some platforms.

  • 增加指定目录给指定编译器去搜索包含文件。这些目录被当前CMakeLists文件以INCLUDE_DIRECTORIES 来加进文件属性。他们也被


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值