cmake简单使用

1.编写hello_world.cpp

#include <iostream>

using namespace std;

int main( int argc,char** argv )
{
      cout<<"hello world"<<endl;
      return 0;

}

放置在code/test

2.在路径下写CMakeLists.txt

project(say)
add_executable(sayHello hello_world.cpp)

~/code/test$ ls

CMakeLists.txt  CMakeLists.txt~  hello_world.cpp  sayHello.out

3.~/code/test$ cmake .
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done

-- Build files have been written to: /home/turtlebot/code/test

4.~/code/test$ make
Scanning dependencies of target sayHello
[100%] Building CXX object CMakeFiles/sayHello.dir/hello_world.cpp.o
Linking CXX executable sayHello

[100%] Built target sayHello

5.~/code/test$ ./sayHello

hello world

~/code/test$ ls
CMakeCache.txt  cmake_install.cmake  CMakeLists.txt~  Makefile

CMakeFiles      CMakeLists.txt       hello_world.cpp  sayHello

注意  CMakeLists.txt       hello_world.cpp  sayHello只有这仨有用,其他可以删

ending....

补充:

~/code/test$ mkdir build

~/code/test$ cd build

~/code/test/build$ cmake ..

~/code/test/build$ make

要删不用的文件直接rm build即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值