比如在打印日志信息的时候定义宏
test.cpp
#include <stdio.h> #define NUMBER 3 int main() { int a = 10; #ifdef DEBUG printf("我是一个程序猿, 我不会爬树...\n"); #endif for(int i=0; i<NUMBER; ++i) { printf("hello, GCC!!!\n"); } return 0; }
CMakeLists.txt
cmake_minimum_required(VERSION 3.15) project(test) # 添加宏定义 add_definitions(-DDEBUG) add_executable(app test.cpp)
标签:cmake,定义,int,cpp,add,test From: https://www.cnblogs.com/xiaoruirui/p/17656704.html