in reply to Problem on XS module loading

You are suffering from the fact that XS was never designed to work with C++.

C++ does Name Mangling. _ZN10Referenced15_perl_mg_vtableE is what the PerlAPI symbol perl_mg_vtable looks like after your C++ compiler has performed its mangling algorithm upon it. As PerlAPIs are built with C, which doesn't use (compatible) name-mangling, ne'er the twain shall meet.

It is very difficult to try and "fix up" such mismatches because C++ name mangling is not standardised across different compilers.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
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.

Replies are listed 'Best First'.
Re^2: Problem on XS
by llancet (Friar) on Oct 28, 2011 at 04:38 UTC
    I guessed it might be caused by C++ issue. But in document perlxs, there is a chapter of "using XS with C++", so there may be some magics?
      so there may be some magics?

      Truthfully, I don't know. I know enough to diagnose the problem, but not enough to resolve it.

      From what I see in that section -- and the rest of the document -- there doesn't appear to be any mention of how to persuade the C++ compiler to not mangle the names of Perl's C APIs called from within the XS code. The normal way of doing this -- thereby allowing C apis to be called from C++ code -- is to use extern "C"{} as described here

      As far as I can tell that would require you to modify Perl's header files, which doesn't seem right.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      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.

      so there may be some magics?

      IIRC, last time you asked about XS/C++ you got links to several working examples, which show

      #ifdef __cplusplus extern "C" {

      So what do you have?

        It seems the problem is g++ modified the symbol name of perl API provided by perl headers, so I tried to surround perl headers within extern:
        extern "C" { #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" #include <stdio.h> }
        But this does not help at all...