cmake:将软件链接到boost :: mpi(使用mpich2)

时间:2011-11-21 20:32:47

标签: cmake mpi boost-mpi

对于这个简单的代码(取自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(需要增加1.4组件)

1 个答案:

答案 0 :(得分: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})