2

对于这个简单的代码(取自 boost-mpi 文档):

#include <boost/serialization/string.hpp>
#include <iostream>
#include <string>
#include <boost/mpi.hpp>

namespace mpi = boost::mpi;

int main(int argc, char *argv[])
{
    mpi::environment env(argc, argv);
    mpi::communicator world;

    if (world.rank() == 0) {
      world.send(1, 0, std::string("Hello"));
      std::string msg;
      world.recv(1, 1, msg);
      std::cout << msg << "!" << std::endl;
    } else if (world.rank() == 1) {
      std::string msg;
      world.recv(0, 0, msg);
      std::cout << msg << ", ";
      std::cout.flush();
      world.send(0, 1, std::string("world"));
    };

  return 0;
};

对于这样的 CMakeLists.txt:

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(mpi-tests CXX)
FIND_PACKAGE(Boost 1.4 COMPONENTS mpi serialization REQUIRED)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(test ${Boost_LIBRARIES})

它找不到 boost_mpi:

CMake Error at /usr/share/cmake/Modules/FindBoost.cmake:1135 (message):
  Unable to find the requested Boost libraries.
  Boost version: 1.47.0
  Boost include path: /usr/include
  The following Boost libraries could not be found:
          boost_mpi

但!我已经安装了下一个软件包:

boost-graph-mpich2
boost-mpich2
boost-mpich2-devel
boost-mpich2-python
mpich2
mpich2-devel

为什么找不到?互联网上有很多例子,人们使用FIND_PACKAGE(Boost 1.4 COMPONENTS mpi REQUIRED)

4

1 回答 1

3

Boost 可能未安装在模块 FindBoost 搜索的位置。您可以通过将变量 BOOST_ROOT 设置为 Boost 安装前缀来指定安装 Boost 的前缀。

我会在您的代码中添加:

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(mpi-tests CXX)
set( BOOST_ROOT "/path/to/boost/install/prefix" )
FIND_PACKAGE(Boost 1.4 COMPONENTS mpi serialization REQUIRED)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(test ${Boost_LIBRARIES})
于 2011-11-22T15:30:11.297 回答