提升库路径包括

时间:2012-08-26 03:45:20

标签: boost mingw

我安装了boost v.1.51.0,目录“boost_1_51_0”位于“/ home / user1 / boost /”下。要安装,我只是在“/ home / user1 / boost /”中解压缩tar文件。我在MinGW上使用C ++编译器。

现在,我正在尝试在代码中包含库。到目前为止我试过

#include </home/user1/boost/boost_1_51_0/libs/unordered/test/objects/test.hpp>  
#include </home/user1/boost/boost_1_51_0/test.hpp>
#include </home/user1/boost/test.hpp>
#include <boost/test.hpp>

以及其他一些人。我甚至尝试将“/ home / user1 / boost /”的windows位置添加到路径中。

我错过了什么。

3 个答案:

答案 0 :(得分:3)

您需要使用命令行参数为编译器提供include目录,例如: -I/home/user1/boost/boost_1_51_0

您可能还想将boost实际安装到系统目录中;有关详细信息,请参阅http://www.boost.org/doc/libs/1_51_0/doc/html/bbv2/installation.html

答案 1 :(得分:3)

使用boost文档中指定的内容(通常与上面<boost/test.hpp>示例一致)。但请适当设置CPPPATH / CXXFLAGS(构建环境)。对于MinGW,您需要添加-I/home/user1/boost/boost_1_51_0/

答案 2 :(得分:3)

#include </home/user1/boost/boost_1_51_0/libs/unordered/test/objects/test.hpp>  

这不起作用。可能会找到该文件,但之后会尝试包含其他文件,例如<boost/config.hpp>,这些文件无法在您的包含路径中找到。

#include </home/user1/boost/boost_1_51_0/test.hpp>
                                         ^^^^^^^^

这不起作用,因为该文件不在该位置!如果您运行ls /home/user1/boost/boost_1_51_0/test.hpp,您将收到错误,因为该文件不存在。

#include </home/user1/boost/test.hpp>
                            ^^^^^^^^

这里也有同样的问题。

无论如何将绝对路径放在#include指令中通常是个坏主意,所以上述所有尝试都是错误的。相反,您应该将文件包含在要使用的文件中:

#include <boost/test.hpp>

为此,您需要告诉编译器在哪里查找,因此您需要设置包含-I dir的包含路径,在您的情况下需要-I /home/user1/boost/boost_1_51_0/,以便编译器查找{{1}在boost/test.hpp中找到/home/user1/boost/boost_1_51_0/,当包含/home/user1/boost/boost_1_51_0/boost/test.hpp时,它会按预期找到boost/config.hpp

但是,现在这会找到/home/user1/boost/boost_1_51_0/boost/config.hpp,但您似乎想要包含其中一个Boost.Undordered单元测试所使用的标头...我不确定您认为自己为何会这样做。通常,您只想在/home/user1/boost/boost_1_51_0/boost.test.hpp下的boost

下包含Boost标头
相关问题