<div>MPICH2 1.3.1:</div><div><br></div><div>$ cat cxx.C </div><div>#include <mpi.h></div><div><br></div><div>int main(int argc,char *argv[])</div><div>{</div><div> MPI_Comm comm;</div><div><br></div><div> MPI::Init(argc,argv);</div>
<div> MPI::Finalize();</div><div> return 0;</div><div>}</div><div><div>$ /opt/mpich2/bin/mpicxx cxx.C </div><div>/opt/mpich2/lib/libmpich.so: undefined reference to `MPL_trfree'</div><div>/opt/mpich2/lib/libmpich.so: undefined reference to `MPL_env2str'</div>
<div>/opt/mpich2/lib/libmpich.so: undefined reference to `MPL_trlevel'</div><div>/opt/mpich2/lib/libmpich.so: undefined reference to `MPL_trvalid'</div><div>/opt/mpich2/lib/libmpich.so: undefined reference to `MPL_trmalloc'</div>
<div>/opt/mpich2/lib/libmpich.so: undefined reference to `MPL_trspace'</div><div>/opt/mpich2/lib/libmpich.so: undefined reference to `MPL_env2range'</div><div>/opt/mpich2/lib/libmpich.so: undefined reference to `MPL_trcalloc'</div>
<div>/opt/mpich2/lib/libmpich.so: undefined reference to `MPL_env2int'</div><div>/opt/mpich2/lib/libmpich.so: undefined reference to `MPL_trdump'</div><div>/opt/mpich2/lib/libmpich.so: undefined reference to `MPL_env2bool'</div>
<div>/opt/mpich2/lib/libmpich.so: undefined reference to `MPL_trstrdup'</div><div>/opt/mpich2/lib/libmpich.so: undefined reference to `MPL_trrealloc'</div><div>/opt/mpich2/lib/libmpich.so: undefined reference to `MPL_TrSetMaxMem'</div>
<div>/opt/mpich2/lib/libmpich.so: undefined reference to `MPL_trinit'</div><div>/opt/mpich2/lib/libmpich.so: undefined reference to `MPL_trDebugLevel'</div><div>/opt/mpich2/lib/libmpich.so: undefined reference to `MPL_trid'</div>
<div>collect2: ld returned 1 exit status</div></div><div><div>$ /opt/mpich2/bin/mpicxx -show cxx.C </div><div>c++ -Wl,--hash-style=gnu -Wl,--as-needed cxx.C -I/opt/mpich2/include -L/opt/mpich2/lib -Wl,-rpath -Wl,/opt/mpich2/lib -lmpichcxx -lmpich -lopa -lmpl -lpthread -lrt</div>
</div><div>$ c++ -Wl,--hash-style=gnu cxx.C -I/opt/mpich2/include -L/opt/mpich2/lib -Wl,-rpath -Wl,/opt/mpich2/lib -lmpichcxx -lmpich -Wl,--as-needed -lopa -lmpl -lpthread -lrt</div><div>$ ./a.out</div><div><br></div><div>
It's not clear to me why the symbols in libmpich.so are not being marked as needed. This does not happen when compiling C programs (with mpicc or mpicxx). It's possible that it is a linker bug, but I have not seen this issue with any other packages. Perhaps it's a circular reference.</div>
<div><br></div><div><div>c++ (GCC) 4.5.1</div></div><div><div>GNU ld (GNU Binutils) 2.20.1.20100521</div></div><div><br></div><div><br></div><div>These link errors aside, I think it is incorrect for MPICH to include user-specified libraries in the --as-needed sequence:</div>
<div><br></div><div><div>$ /opt/mpich2/bin/mpicxx -show cxx.C -lfoo</div><div>c++ -Wl,--hash-style=gnu -Wl,--as-needed cxx.C -lfoo -I/opt/mpich2/include -L/opt/mpich2/lib -Wl,-rpath -Wl,/opt/mpich2/lib -lmpichcxx -lmpich -lopa -lmpl -lpthread -lrt</div>
</div><div><br></div><div>I think the --as-needed should only come after the last of the user's parameters (they may turn it on, but it shouldn't be on by default for their libraries).</div><div><br></div><div>Jed</div>