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 xxcmake_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)