After this, I installed openmpi locally, and now I get the "undefined reference to `MPI::Comm::Comm()' errors.
I also tried add -Wl,-rpath -Wl,/home/visvaldas/local/lib flag to LDFLAGS.
I suspect the linking flags (the first line below) are wrong, but I haven't figured out what's the problem yet.
<...> -o plumed -ldl -lstdc++ -lz -ldl -llapack -lblas -Wl,-rpath -Wl,/home/visvaldas/local/lib -rdynamic -fopenmp
../analysis/Analysis.o: In function `MPI::Cartcomm::Clone() const':
Analysis.cpp:(.text._ZNK3MPI8Cartcomm5CloneEv[_ZNK3MPI8Cartcomm5CloneEv]+0x33): undefined reference to `MPI::Comm::Comm()'
../analysis/Analysis.o: In function `MPI::Graphcomm::Clone() const':
Analysis.cpp:(.text._ZNK3MPI9Graphcomm5CloneEv[_ZNK3MPI9Graphcomm5CloneEv]+0x33): undefined reference to `MPI::Comm::Comm()'
../analysis/Analysis.o: In function `MPI::Intercomm::Merge(bool) const':
Analysis.cpp:(.text._ZNK3MPI9Intercomm5MergeEb[_ZNK3MPI9Intercomm5MergeEb]+0x3b): undefined reference to `MPI::Comm::Comm()'
PS
my LD_LIBRARY_PATH=/home/visvaldas/gcc494/lib/../lib64:/home/visvaldas/local/lib:/home/visvaldas/mvapich2/bin:/home/visvaldas/gromacs20163/lib64:/home/visvaldas/gcc494/lib/../lib64:/home/visvaldas/local/lib/openmpi:/home/visvaldas/mvapich2/bin:/opt/openmpi/lib
I
(duplication due to reload of shell).