【发布时间】:2014-03-10 18:55:49
【问题描述】:
我在使用 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
在程序中,main.cpp 使用 A 类(因此包括a.h),A 类使用 B 类(因此包括b.h)。
那么,我该如何编译这个程序来生成执行文件呢?
我尝试使用以下命令,但它反馈错误:
undefined reference to ~(objects in class A and B)".
command: g++ -Wall -O2 -s main.cpp
我的操作系统是 ubuntu 12.04。我知道如果我用 dev c++ 之类的东西制作一个项目,它会自动将文件链接在一起,但我不想使用它。我还看到了其他链接和来源,但我找不到对自己有用的东西。
【问题讨论】:
标签: c++ header compiler-errors g++ header-files