c++ 多文件、cmakelist 写作简单示例
最编程
2024-04-28 07:14:22
...
记录下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})
上一篇: CAP 的分布式一致协议 (I)
下一篇: 初次了解 ChatGPT