问题
I'm trying to run some MPI programs in xcode 4. I installed openmpi from MacPort by typing sudo port install openmpi
and the installation finished normally. Then I added opt/local/include/openmpi to my user header search paths, dragged the "libmpi.dylib" and "libmpi_cxx.dylib" into my project.
But then when I tried to run the program, I got the following error message:
Undefined symbols for architecture x86_64:
"_MPI_Comm_accept", referenced from:
MPI::Intracomm::Accept(char const*, MPI::Info const&, int) const in main.o
"_MPI_Comm_connect", referenced from:
MPI::Intracomm::Connect(char const*, MPI::Info const&, int) const in main.o
"_MPI_Comm_disconnect", referenced from:
MPI::Comm::Disconnect() in main.o
"_MPI_Comm_get_errhandler", referenced from:
MPI::Comm::Get_errhandler() const in main.o
"_MPI_Comm_set_errhandler", referenced from:
MPI::Comm::Set_errhandler(MPI::Errhandler const&) const in main.o
"_MPI_Comm_spawn", referenced from:
MPI::Intracomm::Spawn(char const*, char const**, int, MPI::Info const&, int) const in main.o
MPI::Intracomm::Spawn(char const*, char const**, int, MPI::Info const&, int, int*) const in main.o
"_MPI_Comm_spawn_multiple", referenced from:
MPI::Intracomm::Spawn_multiple(int, char const**, char const***, int const*, MPI::Info const*, int) in main.o
MPI::Intracomm::Spawn_multiple(int, char const**, char const***, int const*, MPI::Info const*, int, int*) in main.o
"_MPI_Grequest_complete", referenced from:
MPI::Grequest::Complete() in main.o
"_MPI_Op_commutative", referenced from:
MPI::Op::Is_commutative() const in main.o
"_MPI_Reduce_local", referenced from:
MPI::Op::Reduce_local(void const*, void*, int, MPI::Datatype const&) const in main.o
"_MPI_Win_call_errhandler", referenced from:
MPI::Win::Call_errhandler(int) const in main.o
"_MPI_Win_get_errhandler", referenced from:
MPI::Win::Get_errhandler() const in main.o
"_MPI_Win_set_errhandler", referenced from:
MPI::Win::Set_errhandler(MPI::Errhandler const&) const in main.o
"_ompi_mpi_comm_null", referenced from:
MPI::Intracomm::Intracomm(ompi_communicator_t*) in main.o
MPI::Graphcomm::Graphcomm(ompi_communicator_t* const&) in main.o
MPI::Cartcomm::Cartcomm(ompi_communicator_t* const&) in main.o
"_ompi_mpi_comm_world", referenced from:
_main in main.o
"_ompi_mpi_double", referenced from:
_main in main.o
"_ompi_mpi_op_sum", referenced from:
_main in main.o
"_ompi_op_set_cxx_callback", referenced from:
MPI::Op::Init(void (*)(void const*, void*, int, MPI::Datatype const&), bool) in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Am I missing anything in the above installation processes?
回答1:
I had the same problem, when I compiled openmpi from the sources, added header and library search paths, but forgot to add libraries as the linker flags to the build settings. Adding them solved this. You can type mpicc –showme
to see the libraries that are necessary for mpi to run.
回答2:
First be sure to have installed MPI. I personally use brew to do so.
brew update
brew install open-mpi
Then check the requirements for c++:
mpic++ -showme
or mpicc -showme for c
My output with mpic++ is :
clang++ -I/usr/local/Cellar/open-mpi/1.8.6/include -L/usr/local/opt/libevent/lib -L/usr/local/Cellar/open-mpi/1.8.6/lib -lmpi_cxx -lmpi
Then we got the include path, library path and some other flags. From the output of the previous command we got that we need to add:
- "/usr/local/Cellar/open-mpi/1.8.6/include" in the “Search Paths – Header Search Paths”
- "/usr/local/opt/libevent/lib" and "/usr/local/Cellar/open-mpi/1.8.6/lib" in the “Search Paths – Library Search Paths”
- "-lmpi_cxx -lmpi" in the “Linking – Other Linker Flags”
These can be done through the Build Settings option from the Xcode project.
Because mpi need to use it's own program to run ours we need to change the Executable.
- Select "Edit schemes"
- In the dialog box under Info for the Executable choose Other... from the combobox.
- Change it to mpiexec wich is an alias of "orterun". For me it's in /usr/local/Cellar/open-mpi/1.8.6/bin. Note that this is usually an hidden folder. You can open it by pressing
cmd + shift + g
. For running mpiexec need to know as arguments the number of processors and the executable file. So, in the same dialog box under Arguments
- add "-n X" where X is the number of processors you want to use "for this example i will use 2".
- add "$BUILT_PRODUCTS_DIR/$EXECUTABLE_PATH" wich is the combination of environment variables that specify the executable file.
- Then add
<mpi.h>
header to your source code. - Run it and you will see 2 "Hello, World!" (because I use -n 2 for the example).
sources : open-mpi xcode FAQ, Debugging & running MPI programs in Xcode
回答3:
Or just type mpic++ instead of mpicc. That worked for me ;)
来源:https://stackoverflow.com/questions/12593524/how-to-install-openmpi-for-xcode