heheda@linux:~/Linux/loveDBTeacher-v6$ tree
.
├── CMakeLists.txt
└── test.c
0 directories, 2 files
heheda@linux:~/Linux/loveDBTeacher-v6$
- test.c
#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,I am Heheda\n");
}
return 0;
}
- CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(MyProject)
add_definitions(-DDEBUG)
add_executable(app test.c)
执行命令:
1.mkdir build
2.cd build
3.cmake ..
4.make
5./app
执行结果:
heheda@linux:~/Linux/loveDBTeacher-v6$ mkdir build
heheda@linux:~/Linux/loveDBTeacher-v6$ cd build
heheda@linux:~/Linux/loveDBTeacher-v6/build$ cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/heheda/Linux/loveDBTeacher-v6/build
heheda@linux:~/Linux/loveDBTeacher-v6/build$ make
Scanning dependencies of target app
[ 50%] Building C object CMakeFiles/app.dir/test.c.o
[100%] Linking C executable app
[100%] Built target app
heheda@linux:~/Linux/loveDBTeacher-v6/build$ ./app
我是一个程序猿,我不会爬树...
Hello,I am Heheda
Hello,I am Heheda
Hello,I am Heheda
heheda@linux:~/Linux/loveDBTeacher-v6/build$
文章来源地址https://www.toymoban.com/news/detail-809315.html
文章来源:https://www.toymoban.com/news/detail-809315.html
到了这里,关于在CMake中自定义宏 add_definitions(-DDEBUG)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!