您的位置:首页 > 其它

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

2017-12-16 14:37 253 查看

1. ubuntu下CMake安装

apt install cmake


安装后键入

cmake -version


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

2. HelloWorld工程的构建

创建工程目录和文件

mkdir HelloCmake && cd HelloCmake
touch CMakeLists.txt
touch 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 build
cmake ..
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  cmake helloworld