目录
- 一、ubuntu中安装cmake
- 二、单个源文件
-
- 三、多个源文件
- main.c
- test1.c
- test1.h
- CMakeLists.txt的编写
一、ubuntu中安装cmake
sudo apt-get install cmake
cmake --version
二、单个源文件
main.c
#include<stdio.h>
int main()
{
printf("this is my first cmake test\n");
return 0;
}
CMakeLists.txt的编写
- 不能是cmakelist.txt,应该是CMakeLists.txt
mv cmakelists.txt CMakeLists.txt
cmake .
make
- 执行编译生成的可执行文件
三、多个源文件
main.c
#include"test1.h"
int main()
{
printf("this is my first cmake test\n");
print_test_1();
return 0;
}
test1.c
#include "test1.h"
void print_test_1()
{
printf("this is in print_test_1 function\n");
}
test1.h
#ifndef TEST_H_
#define TEST_H_
#include <stdio.h>
void print_test_1();
#endif
CMakeLists.txt的编写
# CMake 最低版本号要求
cmake_minimum_required (VERSION 2.8)
# 项目信息
project (demo1)
# 指定生成目标
add_executable(Demo main.c test1.c)
cmake .
make