我正在尝试编译第三方库,但 g++ 提示以下行:
typedef boost::shared_ptr<MessageConsumer> MessageConsumerPtr;
奇怪的是,文件中没有#include
指令——而且显然应该是这样的;大约有 60 个文件具有相同(或非常相似)的问题。很明显,如果有一个 #include
指令引用相关的 boost header ,这将编译干净。
我的问题是:如何让 g++ 以某种方式自动找到相关符号(在这个问题的所有实例中,它是一个无法找到的 namespace - 通常是 std::
或boost::
) 通过自动处理相关的 header (或其他一些机制)。
谢谢。
编辑
我当前的 g++ 调用如下所示:
g++ -fPIC -O3 -DUSING_PCH -D_REENTRANT -I/usr/include/boost -I./ -c MessageInterpreter.cpp -o MessageInterpreter.o
最佳答案
您可以使用-include
命令行选项:
g++ -include boost/shared_ptr.hpp ...
来自手册页:
-include file Process file as if "#include "file"" appeared as the first line of the primary source file. However, the first directory searched for file is the preprocessor's working directory instead of the directory containing the main source file. If not found there, it is searched for in the remainder of the "#include "..."" search chain as normal.
关于c++ - 编译失败 - 没有#include - boost ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2478933/