工作中 cmakelist 的积累

Demo 记录

  • main.cpp

    #include <stdio.h>
    #include <iostream>
    include "baz.h"
    using namespace std;

    int main()
    {
    DataBuffer db(10);
    cout << " The value of db is " << db.data<< endl;
    }

  • baz.h

    class DataBuffer
    {
    public.
    DataBuffer(int data);

    public:
    int data;
    };

  • baz.cpp

    #include <stdio.h>
    #include <iostream>
    include "baz.h"
    using namespace std;

    DataBuffer::DataBuffer(int data) : data(data)
    {
    }

  • CMakeLists.txt
    注意: 当时一个 bug 是因为 add_executable() 没有把 baz.cpp 添加进去,导致报错 undefined reference o xx

    cmake_minimum_required(VERSION 2.8)

    设置 C 编译器为环境中的 $CC

    set(CMAKE_C_COMPILER $ENV{CC})

    设置 C++ 编译器为环境中的 $CC

    set(CMAKE_CXX_COMPILER $ENV{CXX})

    include_directories(${PROJECT_SOURCE_DIR})

    project(main)

    add_executable(main main.cpp baz.cpp)

相关推荐
感哥2 小时前
C++ 多态
c++
沐怡旸9 小时前
【底层机制】std::string 解决的痛点?是什么?怎么实现的?怎么正确用?
c++·面试
River41612 小时前
Javer 学 c++(十三):引用篇
c++·后端
感哥14 小时前
C++ std::set
c++
侃侃_天下15 小时前
最终的信号类
开发语言·c++·算法
博笙困了15 小时前
AcWing学习——差分
c++·算法
青草地溪水旁16 小时前
设计模式(C++)详解—抽象工厂模式 (Abstract Factory)(2)
c++·设计模式·抽象工厂模式
青草地溪水旁16 小时前
设计模式(C++)详解—抽象工厂模式 (Abstract Factory)(1)
c++·设计模式·抽象工厂模式
感哥16 小时前
C++ std::vector
c++
zl_dfq16 小时前
C++ 之【C++11的简介】(可变参数模板、lambda表达式、function\bind包装器)
c++