[√]添加预处理的2个不同方式:target_compile_definitions / add_definitions

简介: [√]添加预处理的2个不同方式:target_compile_definitions / add_definitions
add_definitions("-Ddef1")
add_executable(${app} ./main.cpp)
target_compile_definitions(${app} PRIVATE def2)

target_compile_definitions(${app} PRIVATE def2)

def1会出现在所有的项目中,跟书写的前后顺序没有任何关系,即时放在target后边,target也会加上

def2仅仅会出现在目标项目中

以下几种写法是等价的

target_compile_definitions(vld PRIVATE "-Ddef")
target_compile_definitions(vld PRIVATE "def")
target_compile_definitions(vld PRIVATE def)

target_compile_definitions向指定的target添加预处理器宏定义

target_compile_definitions是在构建工具中用于设置目标编译定义(Target Compile Definitions)的指令或属性。

在许多构建工具和编译器中,编译定义是一种方式,允许在编译过程中为源代码文件定义预处理变量。这些编译定义可以通过条件编译语句在源代码中进行条件性的编译。

通过使用target_compile_definitions,你可以向构建系统传递特定的编译定义,以便有条件地编译源代码文件或启用特定的功能。

add_definitions是向所有的编译器都添加预处理器宏定义

add_definitions是一个CMake命令,用于向CMake项目添加编译定义(Compile Definitions)。

在CMake中,编译定义是一种预处理变量,它可以在编译过程中为源代码文件定义,并且可以通过条件编译语句在源代码中进行条件性编译。add_definitions命令允许你向整个项目或特定的目标添加编译定义。

使用add_definitions命令的语法如下:

cmakeCopy Code
add_definitions(-DDEFINE_NAME1 -DDEFINE_NAME2 ...)

你可以在命令行中列出要添加的编译定义,每个定义以-D前缀开头。你可以指定一个或多个编译定义,用空格分隔开。

目录
相关文章
|
编译器 C语言
QT编译fabs not declared in this scope
QT编译fabs not declared in this scope
223 0
|
前端开发
vuecli3打包报警告:chunk chunk-common [mini-css-extract-plugin] Conflicting order.
vuecli3打包报警告:chunk chunk-common [mini-css-extract-plugin] Conflicting order.
358 0
vuecli3打包报警告:chunk chunk-common [mini-css-extract-plugin] Conflicting order.
|
10月前
|
人工智能 机器人 测试技术
【CMake报错】Cannot specify compile definitions for target “PRIVATE“ which is not built...
【CMake报错】Cannot specify compile definitions for target “PRIVATE“ which is not built...
136 0
|
10月前
target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target S
target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target S
158 0
Unknown custom element: <add-employee> - did you register the component correctly? For red cursive c
原因: 1.组件名没写对(导入和注册不对应) 2.components少写了个s 3.组件命名最好是驼峰命名 4.导入时语法错误 5.代码中有两个components,后一个的值把前一个覆盖了 6.组件直接循环套用了
116 0
|
10月前
|
Java
JSTL jar包版本错误attribute items does not accept any expressions
确保你在 `items` 属性中使用了一个实际的集合或数组变量,而不是表达式,以解决这个问题。
78 0
|
10月前
|
JavaScript
解决报错did you register the component correctly? For recursive components, make sure to provide the “na
解决报错did you register the component correctly? For recursive components, make sure to provide the “na
|
10月前
|
编解码 JavaScript 编译器
【Vue warn】If this is a native custom element, make sure to exclude it from component resolution ……
【Vue warn】If this is a native custom element, make sure to exclude it from component resolution ……
|
Web App开发 Java
conflicts with existing, non-compatible bean definition of same name and class
使用 Idea CE 创建的 Maven Web 项目,启动时却输出以下错误: Connected to the target VM, address: '127.0.0.1:52165', transport: 'socket'  .
2295 0
错误解决办法:‘NULL’ was not declared in this scope
错误解决办法:‘NULL’ was not declared in this scope
278 0