I am currently compiling two programs.
The same link line produces no error on one, and a whole lot of undefined references on the other one.
The link line is:
/usr/bin/c++ -Wall -pedantic -std=c++11 -fopenmp -O3 -DNDEBUG
CMakeFiles/program.dir/src/main.cpp.o -o program -rdynamic
/home/felix/Development/local/lib/volop/libvolop.so
/home/felix/Development/local/lib/ghost/libghost.so
/home/felix/Development/local/lib/libhwloc.so
/usr/local/lib/libmpicxx.so
/usr/local/lib/libmpi.so -lrt -lpthread -L/usr/lib -lgsl -lgslcblas -lm
/home/felix/Development/PRIMME/libprimme.a
-L/usr/lib -lgsl -lgslcblas -lm -llapack
-L/usr/lib -lgsl -lgslcblas -lm /home/felix/libblas/lib/libopenblas.so
/home/felix/Development/PRIMME/libprimme.a
-llapack
/home/felix/libblas/lib/libopenblas.so
-Wl,-rpath,/home/felix/Development/local/lib/volop:/home/felix/Development/local/lib/ghost:/home/felix/Development/local/lib:/usr/local/lib:/home/felix/libblas/lib
And the associated error:
/home/felix/Development/local/lib/ghost/libghost.so: undefined reference to `MPI_Allgather'
/home/felix/Development/local/lib/ghost/libghost.so: undefined reference to `MPI_Init_thread'
and so on, all MPI Linker errors. However as you can see from the link line mpi is linked in. And in the other program it works just fine.
This is on the same computer with the same compiler. The link line is generated by cmake. The CMakeLists.txt is identical for both programs.
I stop getting linker errors once I start using MPI Methods explicitely in the program which produces the errors. Why?
EDIT: As requested in the comments
ldd /home/felix/Development/local/lib/ghost/libghost.so
linux-vdso.so.1 => (0x00007fff6dff8000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f8d70837000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f8d70531000)
libgomp.so.1 => /usr/lib/x86_64-linux-gnu/libgomp.so.1 (0x00007f8d70321000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f8d7010b000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f8d6feed000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8d6fb26000)
/lib64/ld-linux-x86-64.so.2 (0x00007f8d70f81000)