通过env文件在make文件中包含boost库

时间:2014-03-09 11:57:46

标签: boost makefile

我有一个关于包含boost库来制作文件的问题。这个问题已经在这个论坛和其他人中被多次询问(和回答),但我无法解决我的问题,但是我从那里得到了建议,因为我陷入了一个更基本的阶段。

我正在使用一个现成的make文件,该文件包含boost文件的地址,该文件包含在makefile开头的env文件中。因此,我所要做的就是提供boost库的正确文件夹,但是我似乎提供了错误的地址,因为我收到了无法找到boost库的错误:。

Demo_00.cpp:(.text+0x28): undefined reference to `boost::mpi::environment::environment(int&, char**&, bool)'
Demo_00.cpp:(.text+0x34): undefined reference to `boost::mpi::communicator::communicator()'
Demo_00.cpp:(.text+0x40): undefined reference to `boost::mpi::communicator::rank() const'
Demo_00.cpp:(.text+0x55): undefined reference to `boost::mpi::communicator::rank() const'
Demo_00.cpp:(.text+0x8b): undefined reference to `boost::mpi::environment::~environment()'
Demo_00.cpp:(.text+0xb3): undefined reference to `boost::mpi::environment::~environment()'
collect2: ld returned 1 exit status

env文件的特定部分如下所示:

BOOST_INCLUDE=-I./home/user/Documents/RHPC_2.0/INSTALLATION/boost_1_54_0/
BOOST_LIB_DIR=-L./home/user/Documents/RHPC_2.0/INSTALLATION/boost_1_54_0/stage/lib
BOOST_LIBS=-lboost_mpi-xgcc42-mt -lboost_serialization-xgcc42-mt -lboost_system-xgcc42-mt -lboost_filesystem-xgcc42-mt

我的问题:

在env文件的模板文件中,第一个地址以'... / boost_1_54_0 / include'结尾,我的boost文件夹没有include文件夹(仅在文件夹中有一些)。这是一个问题吗?

我是否需要对BOOST_LIBS进行任何调整?

是否有一种使用cmake识别正确地址的简单方法?我一直在制作cmake纪录片,但却没有明白如何实现这一点。

另外:我刚试过手工编译'链接',这只适用于编译部分,但不适用于链接。这是编译:

/home/user/Documents/RHPC_2.0/INSTALLATION/mpich2-1.4.1p1/bin/mpicxx -c -I/home/user/Documents/RHPC_2.0/INSTALLATION/boost_1_54_0/ -o Demo_00.o Demo_00.cpp

这是链接部分,它不起作用

    /home/user/Documents/RHPC_2.0/INSTALLATION/mpich2-1.4.1p1/bin/mpicxx -L/home/user/Documents/RHPC_2.0/INSTALLATION/boost_1_54_0/stage/lib/ Demo_00.cpp -lboost_mpi-xgcc42-mt -lboost_serialization-xgcc42-mt -lboost_system-xgcc42-mt -lboost_filesystem-xgcc42-mt

执行此命令后,我收到以下错误:

/usr/bin/ld: cannot find -lboost_mpi-xgcc42-mt
/usr/bin/ld: cannot find -lboost_serialization-xgcc42-mt
/usr/bin/ld: cannot find -lboost_system-xgcc42-mt
/usr/bin/ld: cannot find -lboost_filesystem-xgcc42-mt
collect2: ld returned 1 exit status

看来,问题在于最后4个文件,而不是整个boost文件夹。据我所知,上述文件夹/ usr / bin / ld也不存在。

我感谢您的帮助,并再次为再次提出这个话题道歉。

谢谢, 塔尔塔利亚

1 个答案:

答案 0 :(得分:0)

传递给-I的内容应指向其下有boost/*hpp个文件的文件夹(例如boost/shared_ptr.hpp)。

传递给-L的内容应该是传递给-l的所有内容的文件夹(当您说-lthename时,相应的文件名为libthename.so)。< / p>

此外,这些BOOST_ *环境变量应该连接到编译器/链接器命令行(我假设在您的情况下已经自动发生)。