c++ program compilation error

I am getting below error when I am compiling my C++ code on my Mac 10.5.5 OS X machine. I couldn't figure out why this error is happening after I did lot of search online. Can someone help me ?. Thanks in advance.

/usr/local/mpi/bin/mpicxx -DHAVE CONFIGH -I. -I. -I.. -I../advisor -I../otools -I../otools -I../config -I../xg -I/usr/local/hdf5mpi/include -I/usr/local/txphysics-2.1//include -I/usr/local/petscmpi/include -I/usr/local/petscmpi/bmake/darwin9.5.0-c-debug -g -O2 -pipe -Wall -Wno-unused -g -O2 -pipe -DQT3_SUPPORT -DUNIX -DMPI_VERSION -DNOX -c -o parpoi.o parpoi.cpp
In file included from parpoi.cpp:11:
/usr/local/openmpi-1.2.7/include/mpi.h:162:1: warning: "MPI_VERSION" redefined
<command line>:1:1: warning: this is the location of the previous definition
In file included from parpoi.h:18,
from parpoi.cpp:17:
/usr/local/petscmpi/include/petsc.h:137:1: warning: "MPICH SKIPMPICXX" redefined
parpoi.cpp:8:1: warning: this is the location of the previous definition
In file included from parpoi.cpp:17:
parpoi.h:26:1: warning: multi-line comment
parpoi.h:31:1: warning: multi-line comment
/usr/include/c +/4.0.0/i686-apple-darwin9/bits/c+locale.h:60: error: template with C linkage
/usr/include/c++/4.0.0/bits/stringfwd.h:49: error: template with C linkage
/usr/include/c++/4.0.0/bits/stringfwd.h:52: error: template with C linkage
/usr/include/c++/4.0.0/bits/stringfwd.h:56: error: template with C linkage
/usr/include/c++/4.0.0/bits/postypes.h:81: error: template with C linkage
/usr/include/c++/4.0.0/iosfwd:55: error: template with C linkage
/usr/include/c++/4.0.0/iosfwd:58: error: template with C linkage
/usr/include/c++/4.0.0/iosfwd:61: error: template with C linkage
/usr/include/c++/4.0.0/iosfwd:64: error: template with C linkage
/usr/include/c++/4.0.0/iosfwd:67: error: template with C linkage

Mac Book, Mac OS X (10.5.5)

Posted on Sep 30, 2008 8:56 AM

Reply
4 replies

Sep 30, 2008 11:42 AM in response to Selvam

Thanks for your suggestion. I tried initially with the built-in openmpi but had errrors (see below) with that also. My co-developer advised me that build my own openmpi from scratch which he had success in building with other codes. That is why I built in my version of openmpi. I am linking external software PETSc with my c++ code that is the location where this error comes up. The same code works fine on the Linux systems.

/usr/bin/mpicxx -DHAVE CONFIGH -I. -I. -I.. -I../advisor -I../otools -I../otools -I../config -I../xg -I/usr/local/hdf5mpi/include -I/usr/local/txphysics-2.1//include -I/usr/local/petscmpi/include -I/usr/local/petscmpi/bmake/darwin9.5.0-c-debug -g -O2 -pipe -Wall -Wno-unused -g -O2 -pipe -DQT3_SUPPORT -DUNIX -DMPI_VERSION -DNOX -c -o parpoi.o parpoi.cpp
In file included from parpoi.h:18,
from parpoi.cpp:17:
/usr/local/petscmpi/include/petsc.h:137:1: warning: "MPICH SKIPMPICXX" redefined
parpoi.cpp:8:1: warning: this is the location of the previous definition
In file included from parpoi.cpp:17:
parpoi.h:26:1: warning: multi-line comment
parpoi.h:31:1: warning: multi-line comment
/usr/include/c +/4.0.0/i686-apple-darwin9/bits/c+locale.h:60: error: template with C linkage
/usr/include/c++/4.0.0/bits/stringfwd.h:49: error: template with C linkage
/usr/include/c++/4.0.0/bits/stringfwd.h:52: error: template with C linkage
/usr/include/c++/4.0.0/bits/stringfwd.h:56: error: template with C linkage
/usr/include/c++/4.0.0/bits/postypes.h:81: error: template with C linkage
/usr/include/c++/4.0.0/iosfwd:55: error: template with C linkage
/usr/include/c++/4.0.0/iosfwd:58: error: template with C linkage
/usr/include/c++/4.0.0/iosfwd:61: error: template with C linkage
/usr/include/c++/4.0.0/iosfwd:64: error: template with C linkage
/usr/include/c++/4.0.0/iosfwd:67: error: template with C linkage
/usr/include/c++/4.0.0/iosfwd:71: error: template with C linkage
/usr/include/c++/4.0.0/iosfwd:75: error: template with C linkage
/usr/include/c++/4.0.0/iosfwd:79: error: template with C linkage
/usr/include/c++/4.0.0/iosfwd:83: error: template with C linkage

Sep 30, 2008 12:00 PM in response to Selvam

Selvam wrote:
Thanks for your suggestion. I tried initially with the built-in openmpi but had errrors (see below) with that also. My co-developer advised me that build my own openmpi from scratch which he had success in building with other codes. That is why I built in my version of openmpi.


It looks like those are the same errors as with your custom version. I would stick to the provided version unless you have a quantifiable reason to change. Otherwise, if there is a problem later on, and someone asks if you messed with the compiler, you have to sheepishly answer, "Yes, I messed with it".

The same code works fine on the Linux systems.


Means nothing whatsoever. Linux is notorious for being able to compile bad code that no other system will. I don't consider that to be a good thing.

It sounds like some of your headers are all screwed up. That is why you are getting multiple definitions and linkage errors. I found this page which seems to precisely explain your linkage error problem. How to fix it is another problem. You'll probably have to add some #include guards and definitely muck around with code that "works fine in Linux", yet is clearly wrong. Fixing this problem might also fix the multiple includes - and it might not. You may have to do quite a bit of re-arranging.

Often, a fair amount of the effort required to "port" something to MacOS X is actually an effort to fix bugs that were already there.

Oct 1, 2008 2:35 PM in response to Selvam

Thanks for your reply. Your comments were helpful in figuring out the problem with extern "C". I am able to progress in building the code. Apparently my code header file had an extern "C" open and the included mpi.h file had an extern "C" option opened. This was causing the build to fail. Again thanks for your help.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

c++ program compilation error

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.