Hi everyone,

Thanks for the suggestions.

On Thu, Sep 2, 2010 at 6:41 AM, Jeff Squyres <jsquy...@cisco.com> wrote:
> 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.

Ah, I see. That seems unfortunate, but I guess it's out of your hands.

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

I tried the suggestion of simply including mpi.h in C++-mode before
including c-code.h, and that works. I should have thought of that.
(c-code.h still needs to include mpi.h because it's also a standalone
code that uses mpi.)

>
> 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>).

This is also a good suggestions, but I have only scant control over
what's in c-code.h so it's a bit invasive.

In any case I can live with including mpi.h myself first, so I'll go
with that solution.

Regards,

/Patrik

Reply via email to