1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Macports C++ linker fails

Discussion in 'Mac Programming' started by floh, Apr 25, 2012.

  1. macrumors 6502

    #1
    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:

    Code:
    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?
     
  2. macrumors 6502

    #2
    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...
     
  3. macrumors 68040

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

    #4
    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++.
     
  5. macrumors 6502

    #5
    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...
     

Share This Page