wget https://cmake.org/files/v3.11/cmake-3.11.0-rc4-Linux-x86_64.tar.gz
tar zxvf cmake-3.11.0-rc4-Linux-x86_64.tar.gz
sudo mv cmake-3.11.0-rc4-Linux-x86_64 /opt/cmake-3.11
sudo ln -sf /opt/cmake-3.11/bin/* /usr/bin/
验证:
cmake --version
一个简单的例子:
mkdir cmake_test
cd cmake_test
编写一个简单的CPP程序
vim hello.cpp
#include <stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}
编写CMakeLists.txt,与hello.cpp位于同一目录
project(hello)
cmake_minimum_required(VERSION 3.11)
aux_source_directory(. DIR_SRCS)
add_executable(hello ${DIR_SRCS})
并在该目录下输入:
cmake .
然后再输入:
make
最后输入:
./hello
就可得到最后结果: