树莓派使用cmake编译hello world

1.准备好树莓派

2.使用

sudo apt-get install cmake

安装cmake

3.建立项目文件夹

mkdir hello &&cd hello/

4.编写main.c

#include<stdio.h>
int main(void)
{
  printf("hello world\n");
  return 0;        
}

5.编写CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
project(hello)
add_executable(hello main.c)

6.使用 cmake .  在当前文件夹下生成makefile 使用make 编译生成 可执行文件hello

7.运行hello

 tip:若出现

 No CMAKE_CXX_COMPILER could be found.

可以执行 sudo apt-get install -y build-essential 获取必要环境

猜你喜欢

转载自www.cnblogs.com/dataocean/p/12366247.html