ubuntu 16.04 安装cmake3.5.2,及helloworld程序

1、ubuntu 16.04  安装cmake3.5.2

step1:官网下载cmake-3.5.2-Linux-x86_64.tar.gz

step2:解压缩 tar -zxvf cmake-3.5.2-Linux-x86_64.tar.gz,然后发现解压完就已经安装安装完了

step3:配置环境变量

gedit ~/.bashrc

在.bashrc文件末尾添加     export PATH=/home/nie/下载/cmake-3.5.2-Linux-x86_64/bin:$PATH

source ~/.bashrc

step4: 安装完毕之后,进行测试

cmake -version 

显示:

cmake version 3.5.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).

返回cmake版本信息,则说明安装成功

2、cmake的helloworld程序

 在同一目录下如:cd/my_c++/test,编写hello.cppCMakeLists.txt

step1: 编写一个hello.cpp:

#include
#include
using namespace std;
int main(int argc,char const *argv[])
{
   cout<<"hello unbuntu!"<

   return 0;}

step2:编写一个CMakeLists.txt:

cmake_minimum_required(VERSION 3.5.2)

project(hello_nie)

add_executable(TestCmake hello.cpp)

step3:编译并运行

cd/my_c++/test   [进入test目录]

cmake .   [ 生成makefile文件。前提是安装好gcc,才会成功。在安装gcc时,我的软链接写成了sudo ln -si /usr/local/gcc-6.2.0/bin/gcc-6.2.0 gcc-6.2.0,执行cmake .时,出现error:No CMAKE_C_COMPILER could be found.
No CMAKE_CXX_COMPILER could be found.,是因为的 gcc链接被删除,存在的链接是gcc-6.2.0,解决方法:重新做了gcc链接sudo ln -si /usr/local/gcc-6.2.0/bin/gcc-6.2.0 gcc
]

make

./TestCmake

成功输出:hello unbuntu!

参考链接:

https://blog.csdn.net/l1216766050/article/details/77513045

https://blog.csdn.net/flydreamforever/article/details/65454018







你可能感兴趣的:(cmake)