c++ - 编译失败 - 没有#include - boost

标签 c++ boost include g++

我正在尝试编译第三方库,但 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/

相关文章:

c++ - 在 C++ 中初始化为 NULL 的字符串

c++ - 具有 boost 1.56 的卡萨布兰卡因 -Werror 而失败

php - PHP 中 MySQL 的 UTF-8 字符集问题

c++ - 启动进程并重定向其 stdio 的跨平台方式

c++ - 数组拆分为头文件和源文件

C++:提取 boost::variant 元素的大小

java - 如何使用自定义标签库包含 jsp 文件?

ruby - 有什么比 .include 更快的吗?

c++ - 可变存储与不可变存储

c++ - 如何使用 bjam 在 cygwin windows7 i686-w64-mingw32-g++ 中编译 Boost(和链接?)库