小编use*_*194的帖子

使用标头编译不同的.cpp文件

我有一个问题我试图使用GNU g ++一起编译多个文件

我们假设有五个文件:

main.cpp : the main function 
a.h      : the header file of class A 
a.cpp    : the definition of class A 
b.h      : the header file of class B 
b.cpp    : the definition of class B 
Run Code Online (Sandbox Code Playgroud)

在程序中,main.cpp使用类A(因此包括啊),类A使用类B(因此包括bh).

所以在我的主要内容中我刚刚添加了#include"啊"

我正在尝试使用它来编译它

g++ main.cpp -o main
Run Code Online (Sandbox Code Playgroud)

但这不起作用.它给了我一个"未定义的引用"错误.当我将所有类与头文件一起编译时,程序为我提供了所需的输出

有人可以告诉我哪里出错了

c++ g++ header

0
推荐指数
1
解决办法
529
查看次数

标签 统计

c++ ×1

g++ ×1

header ×1