Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Name conflict between MinGW C++ standard library header and Perl development header

by llancet (Friar)
on Nov 12, 2014 at 08:38 UTC ( [id://1106958]=note: print w/replies, xml ) Need Help??


in reply to Re: Name conflict between MinGW C++ standard library header and Perl development header
in thread Name conflict between MinGW C++ standard library header and Perl development header

The issue is located to perl.h, not XSUB.h:

#include "perl.h" #include <iostream> int main() { std::cout << "foo" << std::endl; }
and compile with:
D:\mydoc\projects\GenoEye-0.4.5-build\perl>g++ -ID:/gtk+-2.24.10/inclu +de/cairo -ID:/gtk+-2.24.10/include/glib-2.0 -ID:/gtk+-2.24.10/ lib/glib-2.0/include -ID:/gtk+-2.24.10/include -ID:/gtk+-2.24.10/inclu +de/freetype2 -ID:/gtk+-2.24.10/include/libpng14 -ID:/mydoc/pro jects/GenoEye-0.4.5-Source/src -ID:/mydoc/projects/GenoEye-0.4.5-build +/src -ID:/mydoc/projects/GenoEye-0.4.5-Source -ID:/Strawberry- 5.20.1.1-ia32/perl/lib/CORE -ID:/mydoc/projects/GenoEye-0.4.5-Source/p +erl -g -o test.exe test.cpp

it will reproduce this issue. Also, add #undef write before #include <iostream> won't help.

However, this conflict do not reproduce if I use Inline::CPP. The code below works well:

use strict; use Inline 'CPP' => config => BUILD_NOISY => 1, INC => '-ID:/mydoc/projects/GenoEye-0.4.5-Source/src -ID:/mydoc/p +rojects/GenoEye-0.4.5-Source/perl -ID:/gtk+-2.24.10/include/cairo'; foobar(); use Inline 'CPP' => <<'CODE'; #include <perl.h> #include <iostream> void foobar() { std::cout << "foobar" << std::endl; } CODE
Why there's such big difference? I cannot understand it...
  • Comment on Re^2: Name conflict between MinGW C++ standard library header and Perl development header
  • Select or Download Code

Replies are listed 'Best First'.
Re^3: Name conflict between MinGW C++ standard library header and Perl development header
by syphilis (Archbishop) on Nov 12, 2014 at 09:34 UTC
    Why there's such big difference? I cannot understand it...

    (Yeah ... sorry, not much point running Inline::C scripts when we're dealing with something that's specific to Inline::CPP ;-)

    I don't grok C++, and I can only assume that in your simplified Inline::CPP script, the write() call in ostream has not been made visible. It's definite that 'write' has been defined to 'PerlLIO_write' - just try to use write() in your Inline::CPP script and you'll be able to verify:
    use strict; use Inline 'CPP' => config => BUILD_NOISY => 1; foobar(); use Inline 'CPP' => <<'CODE'; #include <perl.h> // not needed - gets included automatically #include <iostream> void foobar() { std::cout << "foobar" << std::endl; } void break_me(SV * a, SV * b) { write(a, b); } CODE
    That generates the error:
    try_pl_dec5.xs:28:14: error: macro "PerlLIO_write" requires 3 argument +s, but only 2 given write(a, b);
    In ostream, the write() declaration is preceded (next line up) by __ostream_type&. I don't know whether that puts aome sort of condition upon whether the function is visible or not.
    Maybe if you include the same headers in the compilation of your Inline::CPP script as were used for the C++ script then things might start to add up correctly.

    I know it's messy ... XS is like that, but you just have to work through it.

    Cheers,
    Rob

      __ostream_type& is the return type of write() function. Nothing important.

      In C++, "&" is reference. You can just treat it as a sugar for pointers.

Re^3: Name conflict between MinGW C++ standard library header and Perl development header
by Anonymous Monk on Nov 12, 2014 at 08:50 UTC

    Why there's such big difference? I cannot understand it...

    Um, Inline generates XS, look at it and note the differences, right?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1106958]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2024-04-25 15:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found