欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

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