PDA

View Full Version : Macports C++ linker fails




floh
Apr 25, 2012, 07:17 AM
Hey everyone!

I usually don't program C++, so I'm kind of new to this. But the newest collaboration project contains some C++ code, which fails to compile and which I would very much like to test on my Mac.

Because of the lack of a preinstalled MPI on Lion, I mostly use the compilers from Macports. I have XCode 4.2.1 installed (because at the time, 4.3 didn't work with Macports), and for C++ I have installed the following ports:
dyld-headers
gcc44
glib2
openmpi

The compiler (/opt/local/mpiCC) works fine and produces .o files, but the linker fails to find any of the used libraries, the most clear example of error messages would probably be:


mpiCC -dynamic -o <name> <names>.o ../../src/<names>.a -lz
Undefined symbols for architecture x86_64:
"std::cout", referenced from:
...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)


Any ideas? I know that it used to work more or less out of the box on my old laptop, which still had some leftovers from older XCode versions, but it refuses to work on my new one... maybe I'm missing something really obvious?



floh
Apr 25, 2012, 08:12 AM
I kept wiggling around and found a temporary solution: The linker seemed to try to statically link the libstd and the libmpi, which didn't seem right to me.

Adding "-lstdc++ -lmpi_cxx" to the LDFLAGS solved the problem. But is this really how it's supposed to be? Shouldn't the compiler figuer that out for itself and something is broken here?

Comments are still very welcome...

subsonix
Apr 25, 2012, 09:08 AM
Shouldn't the compiler figuer that out for itself and something is broken here?

Comments are still very welcome...

I don't know why you think it should, but you would probably get the most satisfying answers on the macport mailing list.

ScoobyMcDoo
Apr 25, 2012, 11:59 AM
I've never used the mpi stuff, but just googled the man page for mpiCC and saw there is a mpiC++ which will bring in all the c++ libraries. I see the same differences between gcc and g++.

floh
Apr 26, 2012, 08:00 AM
I've never used the mpi stuff, but just googled the man page for mpiCC and saw there is a mpiC++ which will bring in all the c++ libraries. I see the same differences between gcc and g++.

Thanks everyone!

I contacted the Macports mailing list, maybe they can figure out what's going wrong...

ScoobyMcDoo: That's just a naming convention that calls the same binary with some different options. In the Macports openmpi, the gcc equicalent is called "mpicc" and the g++ is called "mpiCC", as far as I understand it. "mpiC++" doesn't exist anywhere in the Macports ressources. Also: The libraries are there. The compiler just seems to be looking in the wrong places or trying to link them statically, which doesn't make any sense.

Still, maybe that hint can help the Macports guys a little more.

As for me: I'm happy with manually adding the LDFLAGS for now, since I adapted our configure script. Still, I am not sure what I missed or did wrong to run into suh problems...