我正在开发 HPC。在该 HPC 上安装了旧版本的 Boost,并且该 boost 库没有 Boost.MPI。我请求管理员将其安装在 HPC 上。但他们要求我将其安装在我的主目录中。所以我在我的主目录中安装了 boost 和 boost.mpi 。 Boost 库似乎工作正常。但是当我尝试使用下面的命令运行以下代码时,出现错误。
测试代码:
#include <boost/mpi/environment.hpp>
#include <boost/mpi/communicator.hpp>
#include <iostream>
namespace mpi = boost::mpi;
int main(int argc, char* argv[])
{
mpi::environment env(argc, argv);
mpi::communicator world;
std::cout << "I am process " << world.rank() << " of " << world.size()
<< "." << std::endl;
return 0;
}
构建命令:
mpiCC -I/home1/username/boost/include
-I/usr/mpi/gcc/openmpi-1.2.8/include/
-L/home1/username/boost/lib
-L/usr/mpi/gcc/openmpi-1.2.8/lib64/openmpi
-lboost_mpi-gcc-mt-1_35 testboostmpi2.cpp
我收到以下错误尖叫:
testboostmpi2.o: In function `main':
testboostmpi2.cpp:(.text+0x59): undefined reference to
`boost::mpi::environment::environment(int&, char**&, bool)'
testboostmpi2.cpp:(.text+0x63): undefined reference to
`boost::mpi::communicator::communicator()'
testboostmpi2.cpp:(.text+0x86): undefined reference to
`boost::mpi::environment::~environment()'
testboostmpi2.cpp:(.text+0xb9): undefined reference to
`boost::mpi::environment::~environment()'
如果你们能提供帮助,我将非常感激。
最佳答案
假设您使用的是 g++,您可以尝试使用 -Wl,--rpath
链接器选项。
mpiCC testboostmpi2.cpp -I/home1/username/boost/include-I/usr/mpi/gcc/openmpi-1.2.8/include/ \
-L/home1/username/boost/lib -L/usr/mpi/gcc/openmpi-1.2.8/lib64/openmpi \
-lboost_mpi-gcc-mt-1_35 -Wl,-rpath -Wl,/home1/username/boost/lib \
-Wl,-rpath -Wl,/usr/mpi/gcc/openmpi-1.2.8/lib64/openmpi
还要以正确的顺序链接,您需要将源文件作为第一个参数,而不是最后一个。
关于mpi - Boost.MPI问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1538535/