cmake入门1之hello world

目录

环境

准备文件

使用cmake

1、生成配置

2、构建

3、运行查看结果

改善使用方式 out-of-source build

文件准备

构建

查看运行结果

总结


环境

ubuntu18

cmake version 3.17.3

准备文件

新建一个文件夹demo1,新建两个文件:CMakeLists.txt、helloworld.c

parallels@Lincoln:~/workspace/cmakedemo/demo1$ pwd
/home/parallels/workspace/cmakedemo/demo1
parallels@Lincoln:~/workspace/cmakedemo/demo1$ tree
.
├── CMakeLists.txt
└── helloworld.c

helloworld.c文件源码如下:

#include <stdio.h>

int main() {
    printf("hello world\n");
    return 0;
}

CMakeLists.txt:cmake的配置文件

#设置cmake的最小版本要求
cmake_minimum_required(VERSION 3.10)
#设置工程名字为 ylk_hello
project(ylk_hello)
#使用helloworld.c生成可执行程序hello
add_executable(hello helloworld.c)

使用cmake

1、生成配置

 cmake 其中 表示在当前目录搜索CMakeLists.txt(上面创建的)

parallels@Lincoln:~/workspace/cmakedemo/demo1$ cmake .
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.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 co
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值