多个文件编译在linux下编译,下面有三个文件,分别是1.cpp 和 2.cpp 和myhead.h 文件。
1.cpp
#include
#include "myhead.h"
using namespace std;
int main(){
print();
cout<
return 0;
}
2.cpp
#include
#include "myhead.h"
using namespace std;
void print(){
std::cout<
cout<<
}
myhead.h
#ifndef __myhead_h
#define __myhead_h
void print();
#endif
假如他们都在一个目录下面,那么编译流程:
g++ -c 2.cpp #将2.cpp 编译成2.o 文件
g++ 1.cpp -o a.out 2.o #多个文件一起链接
or
g++ -c 2.cpp
g++ -c 1.cpp
g++ 1.o 2.o -o test
当然,没有头文件,两个.c文件也是可以编译的。如下:
1.cpp文件
#include
using namespace std;
void fn();
本文发布于:2024-01-30 02:55:29,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170655453118734.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |