cmake_minimum_required( VERSION 2.8 )
project(test)
add_executable(${PROJECT_NAME} test.c)
执行编译、运行:
[root@hadoop3 test]# ls
build CMakeLists.txt test.c
[root@hadoop3 test]#[root@hadoop3 test]#[root@hadoop3 test]# tree.
├── build
├── CMakeLists.txt
└── test.c
1 directory, 2 files
[root@hadoop3 test]# cd build/[root@hadoop3 build]# cmake ../
-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- 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
-- 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
-- Configuring done
-- Generating done
-- Build files have been written to: /home/hero/code/test/build
[root@hadoop3 build]# make
Scanning dependencies of target test[100%] Building C object CMakeFiles/test.dir/test.c.o
Linking C executable test[100%] Built target test[root@hadoop3 build]# ./test
Hello world
[root@hadoop3 build]#