如下,prj是空文件夹;
add.h;
- #include
-
- using namespace std;
-
- int add1(int a, int b);
num.h;
- int num1=100;
- int num2=301;
add.cpp;
- #include "add.h"
-
- int add1(int i, int j)
- {
- return i + j;
- }
main.cpp;
- #include
- #include "add.h"
- #include "num.h"
-
- int main()
- {
- cout << add1(num1, num2) << endl;
- getch();
- return 0;
- }
CMakeLists.txt如下;
- cmake_minimum_required(VERSION 3.10)
- project(myadd VERSION 1.0)
- aux_source_directory(. ALL_SRCS)
- add_executable(myadd ${ALL_SRCS})
project指令