栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

cmake 精简入门

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

cmake 精简入门

c++文件源代码:main.cc

#include 
#include 

class MyCalc
{
public:
  int a;
  int b;
  int getAdd();
};

int MyCalc::getAdd()
{
  return a+b;
}

int main(int argc, char *argv[])
{
  printf("====Welcome cpp test=======n");
  MyCalc mc;
  mc.a=10;
  mc.b=90;
  printf("Add res = %d n", mc.getAdd() );

  return 0;
}

当前目录下的CMakeLists.txt

# CMake 最低版本号要求
cmake_minimum_required (VERSION 2.8)
# 项目信息
project (Demo1)
# 指定生成目标
add_executable(Demo main.cc)

然后在当前目录下新建一个文件夹build (任意定义,推荐名称build)

然后进入build目录下终端运行命令: cmake ..

(cmake后跟着点点,代表运行当前目录前一级的Lists配置,输出的缓存文件在当前build目录)

终端显示:

-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- 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/bnis/Desktop/TestCode/build

看到build目录下生成很多中间文件,其中有个是Makefile,然后执行make  

[ 50%] Building CXX object CMakeFiles/Demo.dir/main.cc.o
[100%] Linking CXX executable Demo
[100%] Built target Demo

得到最终输出执行文件Demo

若需要重新cmake,需要清空build文件夹。在build当前目录运行 rm -rf *

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/971121.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号