syphilis has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I've built the libproj library with mingw (for use with PDL on x64 Windows perl) but attempted access to that library fails at the build stage because both projects.h (from the libproj library) and winreg.h (from the mingw x64 compiler) define PVALUE.

Here's a simple script and consequent error message that hopefully makes the problem clear:
use warnings; use Inline C => <<'EOC'; #include <projects.h> SV * foo() { printf("Hello World\n"); } EOC foo();
And the error it produces:
In file included from try_pl_f857.xs:6: C:\_64\msys\1.0\local\include/projects.h:150: error: conflicting types + for 'PVALUE' c:/_64/mingw64/lib/gcc/../../x86_64-w64-mingw32/include/winreg.h:76: n +ote: previous declaration of 'PVALUE' was here dmake: Error code 129, while making 'try_pl_f857.o'
Line 150 of projects.h:
typedef union { double f; int i; char *s; } PVALUE;
and line 76 of winreg.h:
typedef PVALUEA PVALUE;
One solution is to change the typedef in projects.h to something else (I chose _P_VALUE), and to amend the other libproj source files accordingly, then re-compile and re-install the library. That's fairly simple as PVALUE crops up in only a few places ... and that works well.

But is there a smarter way to approach this sort of problem - something I could do in that Inline::C script that enables it to run without having to alter projects.h, and without having to remove the #include <projects.h> ?

Cheers,
Rob

Replies are listed 'Best First'.
Re: [OT] "conflicting types" in C headers.
by BrowserUk (Patriarch) on Apr 30, 2010 at 08:55 UTC

    That's the problem with C's flat namespace. C++ namespaces address that, but at significant cost.

    One possibility is to add something like:

    #if defined( _WINREG_H ) && !defined( _PROJECT_H ) typedef PVALUEA PVALUE; #elif defined( _PROJECT_H ) && !defined( _WINREG_H ) typedef union { double f; int i; char *s; } PVALUE; #else assert( "File " __FILE__ "requires PVALUE defined from both winreg.h a +nd project.h" == NULL ); #endif

    That probably doesn't compile anywhere, but you get the idea.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.