【发布时间】:2011-06-08 23:23:18
【问题描述】:
我可以访问一个大型 C++ 项目,其中包含大量文件和一个非常复杂的 makefile,由 automake 和朋友提供
这是目录结构的一个想法。
otherproject/
folder1/
some_headers.h
some_files.cpp
...
folderN/
more_headers.h
more_files.cpp
build/
lots_of things here
objs/
lots_of_stuff.o
an_executable_I_dont_need.exe
my_stuff/
my_program.cpp
我想使用大项目中的一个类,声明为“some_header.h”
/* my_program.cpp */
#include "some_header.h"
int main()
{
ThatClass x;
x.frobnicate();
}
我通过煞费苦心地将大量“-I”选项传递给 gcc 来编译我的文件,以便它可以找到所有头文件
g++ my_program.cpp -c -o myprog.o -I../other/folder1 ... -I../other/folderN
在编译时,我必须手动包含他所有的“.o”,这可能是矫枉过正
g++ -o my_executable myprog.o ../other/build/objs/*.o
但是,我不仅需要手动从列表中删除他的“main.o”,而且这还不够,因为我忘记了还链接到他碰巧使用的所有库。
otherproject/build/objs/StreamBuffer.h:50: undefined reference to `gzread'
此时我开始觉得我可能做错了什么。 我应该如何进行?解决此类问题的常用方法和最佳方法是什么?
如果需要执行特定于平台的操作,我需要它在 Linux 上工作。
【问题讨论】:
-
ThatClass x();是最令人头疼的解析的经典案例。你的意思可能是ThatClass x;
标签: c++ compilation autotools automake