1.项目目录结构 2.文件内容 swap.h
#pragma once
#include <iostream>
class swap{
public:
swap(int a,int b)
{
this->_a = a;
this->_b = b;
}
void run();
void printInfo();
private:
int _a;
int _b;
};
swap.cpp
#include "swap.h"
void swap::run()
{
int temp;
temp = _a;
_a = _b;
_b = temp;
}
void swap::printInfo()
{
std::cout<<"_a="<<_a<<std::endl;
std::cout<<"_b="<<_b<<std::endl;
}
main.cpp
#include "swap.h"
int main(int argc,char **argv)
{
swap swap(10,20);
swap.printInfo();
swap.run();
swap.printInfo();
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 2.8.3)
PROJECT (SWAP)
include_directories(include)
ADD_SUBDIRECTORY(src bin)
./src/CMakeLists.txt
ADD_EXECUTABLE(swap main.cpp swap.cpp)
3.外部构建
$ mkdir build
$ cd build
$ cmake ..
$ make
参考资料 CMake简明教程 Clion的配置文件 CMakeLists.txt 语法介绍与实例
|