• UBuntu CMake工程配置基础


    UBuntu CMake工程配置基础 - sheismylife的专栏 - 博客频道 - CSDN.NET


    UBuntu CMake工程配置基础


    分类:
    C++


    1024人阅读
    评论(1)
    收藏
    举报
     

    install CMake

    我用CMake并不关注它的跨平台特性,因为我只专注于64位 Linux C++ server领域。
    sudo apt-get install cmake

    chenshu@chenshu-ubuntu:~$ cmake —version
    cmake version 2.8.3

    HelloWorld工程

    mkdir -p examples/helloworld
    cd examples/helloworld

    创建main.cpp 文件,代码如下:

    1. #include <stdio.h>  
    2. int main()  
    3. {  
    4.     printf("Hello World from Main!\n");  
    5.     return 0;  
    6. }  


    创建CMakeLists.txt文件,配置如下:

    1. PROJECT (HELLOWorld)  
    2. SET(SRC_LIST main.cpp)  
    3. MESSAGE(STATUS "This is BINARY dir " ${HELLO_BINARY_DIR})  
    4. MESSAGE(STATUS "This is SOURCE dir "${HELLO_SOURCE_DIR})  
    5. ADD_EXECUTABLE(hello ${SRC_LIST})  


    在同目录下,运行cmake .
    chenshu@chenshu-ubuntu:~/Ubuntu One/c++/cmake/examples/helloworld$ cmake .
    — The C compiler identification is GNU
    — The CXX compiler identification is GNU
    — Check for working C compiler: /usr/bin/gcc
    — Check for working C compiler: /usr/bin/gcc — works
    — Detecting C compiler ABI info
    — Detecting C compiler ABI info - 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
    — This is BINARY dir /home/chenshu/Ubuntu One/c++/cmake/examples/helloworld
    — This is SOURCE dir /home/chenshu/Ubuntu One/c++/cmake/examples/helloworld
    — Configuring done
    — Generating done
    — Build files have been written to: /home/chenshu/Ubuntu One/c++/cmake/examples/helloworld


    Makefile以及其他一些文件被cmake生成了。执行make命令,hello二进制文件被编译出来。运行./hello,可以看到结果。
    Hello World from Main!

    make VERBOSE=1 可以看到详细的编译过程。
    make clean 就可以清理工程

    外部构建

    HelloWorld采用内部构建,cmake产生的代码和自己的源代码文件在同一个目录,非常不好。因此需要采用cmake的外部构建方式。
    创建helloworld2目录
    这次创建一个src目录存放源代码,doc目录存放项目文档,
    CMakeLists.txt需要出现在项目根目录和src目录中。
    项目根目录下的内容如下:
    project (HelloWorld2)
    add_subdirectory(src bin)
    src目录下内容如下:
    add_executable(hello2 main.cpp)

    创建一个build目录
    cd build
    cmake ..
    make
    build/bin下会找到hello2可执行文件。

    支持gdb调试

    在src/CMakeLists.txt文件中添加一行: set(CMAKE_BUILD_TYPE Debug)

  • 相关阅读:
    ElasticSearch(十二):Spring Data ElasticSearch 的使用(二)
    ElasticSearch(十):Elasticsearch集群配置
    Linux下设置postgresql数据库开机启动
    PostgreSQL分区表实现——pg_pathman安装、配置
    Postgresql日志配置
    Linux CentOS 7 安装PostgreSQL 9.5.17 (源码编译)
    Docker(5):Docker镜像基本操作(上)
    数学建模之路----遗传算法
    MATBLAB学习笔记----基础绘图
    ffmpeg音频视频转格式工具使用
  • 原文地址:https://www.cnblogs.com/lexus/p/2695251.html
Copyright © 2020-2023  润新知