heheda@linux:~/Linux/loveDBTeacher-v6$ tree
.
├── CMakeLists.txt
└── test.c0 directories, 2 files
heheda@linux:~/Linux/loveDBTeacher-v6$
#include <stdio.h>
#define NUMBER 3int main() {int a = 10;
#ifdef DEBUGprintf("我是一个程序猿,我不会爬树...\n");
#endiffor(int i=0;i<NUMBER;i++) {printf("Hello,I am Heheda\n");}return 0;
}
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$