【问题标题】:Boost.MPI gives Undefined symbols for architecture x86_64Boost.MPI 为架构 x86_64 提供未定义符号
【发布时间】:2017-07-16 15:32:29
【问题描述】:

我正在尝试运行基本的"Hello, World!" example

#include <boost/mpi/environment.hpp>
#include <boost/mpi/communicator.hpp>
#include <iostream>
namespace mpi = boost::mpi;

int main()
{
  mpi::environment env;
  mpi::communicator world;
  std::cout << "I am process " << world.rank() << " of " << world.size()
            << "." << std::endl;
  return 0;
}

我已经尝试了许多变体来运行这个程序:

mpic++ -I /usr/local/include/ test.cpp -o test -lboost_system

还有:

mpic++ -I /usr/local/include/boost test.cpp -o test -lboost_system

并使用mpiccclang++ 作为替代。每种组合都会出现以下错误:

Undefined symbols for architecture x86_64:
  "boost::mpi::environment::environment(bool)", referenced from:
      _main in test-b0215f.o
  "boost::mpi::environment::~environment()", referenced from:
      _main in test-b0215f.o
  "boost::mpi::communicator::communicator()", referenced from:
      _main in test-b0215f.o
  "boost::mpi::communicator::rank() const", referenced from:
      _main in test-b0215f.o
  "boost::mpi::communicator::size() const", referenced from:
      _main in test-b0215f.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Homebrew 说 MPICH2 和 boost1.63.0 都已安装。我可以通过编译然后运行this program:来确认mpic++运行

   // required MPI include file  
   #include "mpi.h"
   #include <stdio.h>

   int main(int argc, char *argv[]) {
   int  numtasks, rank, len, rc; 
   char hostname[MPI_MAX_PROCESSOR_NAME];

   // initialize MPI  
   MPI_Init(&argc,&argv);

   // get number of tasks 
   MPI_Comm_size(MPI_COMM_WORLD,&numtasks);

   // get my rank  
   MPI_Comm_rank(MPI_COMM_WORLD,&rank);

   // this one is obvious  
   MPI_Get_processor_name(hostname, &len);
   printf ("Number of tasks= %d My rank= %d Running on %s\n", numtasks,rank,hostname);


        // do some work with message passing 


   // done with MPI  
   MPI_Finalize();
   }

这会产生正确的输出。

我还通过编译并成功运行 Boost "Hello, World!" 验证了(至少部分)Boost 已安装

//
// timer.cpp
// ~~~~~~~~~
//
// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#include <iostream>
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

int main()
{
  boost::asio::io_service io;

  boost::asio::deadline_timer t(io, boost::posix_time::seconds(5));
  t.wait();

  std::cout << "Hello, world!" << std::endl;

  return 0;
}

与:

clang++ -I /usr/local/include/ timer.cpp -o timer -lboost_system

如何让 Boost.MPI 示例运行?

【问题讨论】:

    标签: c++ boost mpi


    【解决方案1】:

    当您从 boost 中得到链接器错误时,您通常会忘记链接到 boost 库。

    还有一个 boost_mpi 库,所以你应该编译

    clang++ -I /usr/local/include/ timer.cpp -o timer -lboost_system -lboost_mpi
    

    请注意,您需要一个支持 mpi 的 boost 版本。

    【讨论】:

    • 我的电脑似乎找不到它ld: library not found for -lboost_mpi。也许 Homebrew 默认不安装它还是什么?
    • 所以,有一个 boost-mpi 的 brew 公式。我要试试这个,看看它是否有效。
    • 是的,好像是这样,检查stackoverflow.com/questions/13143409/…
    • 好的,将链接添加到我的答案中。希望这足以回答您的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-07
    • 2012-07-20
    • 1970-01-01
    • 2015-08-23
    • 2014-05-27
    • 2017-07-06
    • 2016-06-20
    相关资源
    最近更新 更多