记录下c++多文件cmakelist编写流程:
目录结构大致如下:
1、swap.h
#include <iostream>
#include <vector>
#include <string>
using namespace std;
void swap(int *a,int *b);
2、swap.cpp
#include "swap.h"
void swap(int *a,int *b)
{
int tmp=*b;
*b=*a;
*a=tmp;
}
3、test.cpp
#include "swap.h"
int main()
{
int a=10,b=20;
swap(&a,&b);
cout <<a<<b<< endl;
cin.get();
}
4、CMakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(main)
set(SOURCE_FILES test.cpp swap.cpp)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})