2017-02-25 53 views
0

我试图运行基本"Hello, World!" example未定义的符号:Boost.MPI给出了建筑x86_64的

#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) 

家酿说,双方MPICH2和boost1.63.0安装。我可以通过编译,然后运行this program:

// 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(); 
    } 

将会产生正确的输出确认mpic++运行。

我也验证了(至少部分)升压被编译并成功运行安装Boost "Hello, World!"

// 
// 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例子跑步?

回答

1

当你从boost中得到链接器错误时,你通常忘了链接到boost库。

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

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

注意,你需要一个升压版本与MPI支持编译。

+0

似乎我的计算机无法找到它'LD:库找不到-lboost_mpi'。也许Homebrew不会默认安装它或者什么? – Dair

+0

因此,有一个boost-mpi的酿造公式。我会试试看看它是否有效。 – Dair

+0

是的,似乎是这样,检查http://stackoverflow.com/questions/13143409/how-to-build-boost-with-mpi-support-on-homebrew – overseas