#include "test1.h"
int main() {
test1();
return 0;
}
#ifndef __TEST1_H
#define __TEST1_H
const int kVar = 1; // 测试不使用extern
void test1();
#endif
#include <iostream>
#include "test1.h"
using namespace std;
void test1() {
cout << "in test1: " << kVar << endl;
}
g++ -c main.cpp test1.cpp
// -c Compile and assemble, but do not link.
// g++ -c 将为每个.cpp文件生成对应的目标文件,如下所示的main.o, test1.o
// $ ls
// main.cpp main.o test1.cpp test1.h test1.o
g++ -o main main.o test1.o
// -o <file> Place the output into <file>.
// g++ -o 对多个.o文件进行链接,生成.exe文件
// $ ls
// main.cpp main.exe main.o test1.cpp test1.h test1.o
// $ ./main
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。