2017-02-25 34 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

相關問題