On Aug 31, 2010, at 5:39 PM, Patrik Jonsson wrote:

> It seems a bit presumptuous of mpi.h to just include mpicxx.h just
> because __cplusplus is defined, since that makes it impossible to link
> C MPI code from C++.

The MPI standard requires that <mpi.h> work in both C and C++ applications.  It 
also requires that <mpi.h> include all the C++ binding prototypes when 
relevant.  Hence, there's not much we can do here.

> I've had to resort to something like
> 
> #ifdef __cplusplus
> #undef __cplusplus
> #include <mpi.h>
> #define __cplusplus
> #else
> #include <mpi.h>
> #endif

As you noted, that doesn't seem like a good idea.

> in c-code.h, which seems to work but isn't exactly smooth. Is there
> another way around this, or has linking C MPI code with C++ never come
> up before?

Just to be clear: this isn't a linking issue; it's a compiling issue.  

As Lisandro noted, it's probably best to separate <mpi.h> outside of your 
<c-code.h> file.

Or, you can make your <c-code.h> file be safe for C++ by doing something like 
in c-code.h:

#include <mpi.h>

#ifdef __cplusplus
#extern "C" {
#endif
...all your C declarations...
#ifdef __cplusplus
}
#endif

This is probably preferable because then your <c-code.h> is safe for both C and 
C++, and you keep <mpi.h> contained inside it (assumedly preserving some 
abstraction barriers in your code by keeping the MPI prototypes bundled with 
<c-code.h>).

-- 
Jeff Squyres
jsquy...@cisco.com
For corporate legal information go to:
http://www.cisco.com/web/about/doing_business/legal/cri/


Reply via email to