CMake入门使用(一)安装及HelloWorld的构建

来源:互联网 发布:linux安装软件的方式 编辑:程序博客网 时间:2024/06/13 07:22

1. ubuntu下CMake安装

apt install cmake

安装后键入

cmake -version

如果显示CMake的版本号,表示安装成功

2. HelloWorld工程的构建

创建工程目录和文件

mkdir HelloCmake && cd HelloCmaketouch CMakeLists.txttouch helloworld.cpp

helloworld.cpp中敲入

#include <iostream>int main(int argc, char** argv ){    std::cout << "Hello World!" << std::endl;    return 0;}

CMakeLists.txt中敲入

cmake_minimum_required(VERSION 2.8)project( HelloWorld )set( SRCFILES helloworld.cpp )add_executable( hello ${SRCFILES} )

准备工作完成,接下来是CMake三部曲

mkdir build && cd buildcmake ..make

然后执行

./hello

就OK啦
这里写图片描述

完整工程上传至git上https://github.com/fujikoli/CMakeExamples

PS:如果遇见

No CMAKE_CXX_COMPILER could be found.

Tell CMake where to find the compiler by setting either the environment
variable “CXX” or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
见:http://blog.csdn.net/xx352890098/article/details/78819852

原创粉丝点击