2016-11-12 4 views
0

Ich habe versucht, MPI mit C++ den folgenden Code Boost:kann nicht einfach Boost-MPI Beispiel kompilieren

#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() << "on " << world.size() << "." << std::endl; 
    return 0; 
} 

Und ich habe Boost-mpi kompiliert und installiert:

~ ls /usr/local/include/boost | grep mpi 
mpi 
mpi.hpp 
~ ls /usr/local/lib | grep mpi 
libboost_mpi.a 
libboost_mpi.so 
libboost_mpi.so.1.62.0 

~ ls /usr/local/lib | grep serialization                     
libboost_serialization.a 
libboost_serialization.so 
libboost_serialization.so.1.62.0 
libboost_wserialization.a 
libboost_wserialization.so 
libboost_wserialization.so.1.62.0 

Kompilieren

mit
mpic++ -L/usr/local/lib -I/usr/local/include/boost/mpi -lboost_mpi-gcc-mt-1_35 -lboost_serialization MPIBoostBindingExample.cpp -o MPIBoostBindingExample 

Aber noch habe Fehler zu sagen:

/tmp/ccKVwnKR.o: In function `main': 
MPIBoostBindingExample.cpp:(.text+0x27): undefined reference to `boost::mpi::environment::environment(bool)' 
MPIBoostBindingExample.cpp:(.text+0x33): undefined reference to `boost::mpi::communicator::communicator()' 
MPIBoostBindingExample.cpp:(.text+0x3f): undefined reference to `boost::mpi::communicator::size() const' 
MPIBoostBindingExample.cpp:(.text+0x4d): undefined reference to `boost::mpi::communicator::rank() const' 
MPIBoostBindingExample.cpp:(.text+0xb8): undefined reference to `boost::mpi::environment::~environment()' 
MPIBoostBindingExample.cpp:(.text+0xeb): undefined reference to `boost::mpi::environment::~environment()' 
collect2: error: ld returned 1 exit status 

Irgendwelche Hilfe?

Antwort

1

Funktioniert für mich (Ubuntu 16.04), wenn ich nur -lboost_mpi hinzufügen.

Ihr Code (Modulo kleinere Änderungen):

[email protected]:/tmp$ cat boostmpi.cpp 
#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() 
      << " on " << world.size() << "." << std::endl; 
    return 0; 
} 
[email protected]:/tmp$ 

Und wir gerade mit der oben erwähnten Bibliothek kompilieren (die mpic++ nicht über standardmäßig weiß)

[email protected]:/tmp$ mpic++ -o boostmpi boostmpi.cpp -lboost_mpi 
[email protected]:/tmp$ orterun ./boostmpi 
I am process 2 on 4. 
I am process 3 on 4. 
I am process 0 on 4. 
I am process 1 on 4. 
[email protected]:/tmp$ 

Dies wird durch die Tatsache geholfen wird Boost-Header und andere Bibliotheken haben den Status "System", dh sind mit zusätzlichen Flags -I oder -L erreichbar.

+0

es funktioniert - und das dauerte mich einen ganzen Tag des Compilierens und Entfernen und neu installieren 'boost' ... vielleicht bin ich nicht geschnitten, Software dev überhaupt zu sein ... –

+1

Verzweifeln Sie nicht, wir waren alle Dort. Der Schlüssel ist zu lernen ... aus den Fehlermeldungen des Compilers, oder in diesem Fall des Linkers –

Verwandte Themen