in reply to Re^3: SWIG and conflicting definitions
in thread SWIG and conflicting definitions

Thanks - that is progress. After making that change, STDERR is down to 21 lines. This is the full output:

pwiz_swigbindings_wrap.cxx:1554:35: error: ‘CV’ has not been declared SWIGEXPORT void SWIG_init (pTHXo_ CV* cv); ^ pwiz_swigbindings_wrap.cxx: In function ‘void boot_pwiz_swigbindings(P +erlInterpreter*, __perl_CV*)’: pwiz_swigbindings_wrap.cxx:748:52: error: conflicting declaration of C + function ‘void boot_pwiz_swigbindings(PerlInterpreter*, __perl_CV*)’ #define XSPROTO(name) void name(pTHX_ __perl_CV* cv) ^ /usr/lib/x86_64-linux-gnu/perl/5.20/CORE/XSUB.h:145:44: note: in expan +sion of macro ‘XSPROTO’ # define XS_EXTERNAL(name) extern "C" XSPROTO(name) ^ /usr/lib/x86_64-linux-gnu/perl/5.20/CORE/XSUB.h:156:18: note: in expan +sion of macro ‘XS_EXTERNAL’ #define XS(name) XS_EXTERNAL(name) ^ pwiz_swigbindings_wrap.cxx:6265:1: note: in expansion of macro ‘XS’ XS(SWIG_init) { ^ pwiz_swigbindings_wrap.cxx:1531:22: note: previous declaration ‘void b +oot_pwiz_swigbindings(PerlInterpreter*, int*)’ #define SWIG_init boot_pwiz_swigbindings ^ pwiz_swigbindings_wrap.cxx:1554:17: note: in expansion of macro ‘SWIG_ +init’ SWIGEXPORT void SWIG_init (pTHXo_ CV* cv); ^

Here is the context refered to in the first line:

1546 1547 #ifdef __cplusplus 1548 extern "C" 1549 #endif 1550 #ifndef PERL_OBJECT 1551 #ifndef MULTIPLICITY 1552 SWIGEXPORT void SWIG_init (CV* cv); 1553 #else 1554 SWIGEXPORT void SWIG_init (pTHXo_ CV* cv); 1555 #endif 1556 #else 1557 SWIGEXPORT void SWIG_init (CV *cv, CPerlObj *); 1558 #endif 1559

I really appreciate the help so far. I'd love to get this working but troubleshooting at this level is beyond me.

Replies are listed 'Best First'.
Re^5: SWIG and conflicting definitions
by Anonymous Monk on Jan 08, 2016 at 16:53 UTC

    You could use

    #undef XSPROTO #define XSPROTO(name) void name(pTHX_ struct cv* cv)
    This should be compatible with the typedef. An incomplete type declaration
    struct cv;
    can't hurt either, though that shouldn't be necessary. Try this without that sneaky #define CV ...

    However, your boot_pwiz_swigbindings takes two arguments, whereas SWIG_init is expected to take one. Something needs a fix there as well.

      I agree mostly. Using
      #include "perl.h" #include "XSUB.h" #undef XSPROTO #define XSPROTO(name) void name(pTHX_ struct cv* cv)
      instead of
      #define CV __perl_CV #include "perl.h" #include "XSUB.h" #undef XSPROTO #define XSPROTO(name) void name(pTHX_ __perl_CV* cv) #undef CV
      is much more elegant and better. But both variants should work.

      However SWIG_init is declared with two parameters.

      In 'SWIGEXPORT void SWIG_init (pTHXo_ CV* cv);' macro 'pTHHXo_' expands to 'PerlInterpreter*,'.

      With the comma at the end there are suddenly two parameters.

      This worked!

      #include "EXTERN.h" #include "perl.h" #include "XSUB.h" /* These lines are needed to avoid collisions */ #undef XSPROTO #define XSPROTO(name) void name(pTHX_ struct cv* cv)

      Despite the additional caveats given by you and hexcoder, adding just those last two lines as suggested allowed things to compile without error, and I tested the resulting module/library with a basic call and got the expected response. There's still a lot of work to do cleaning up the interface and getting it to use existing system libraries instead of pulling everything into the module shared object file, but I'm willing to spend the time now that I know the basics work.

      Thanks to both of you for the help. I'd give you both more upvotes if I could.

Re^5: SWIG and conflicting definitions
by hexcoder (Curate) on Jan 08, 2016 at 22:36 UTC
    As suggested by Anonymous Monk you should modify the declarations. Substitute CV by struct cv in lines 1552, 1554 and 1557.

    But (as remarked by Anonymous Monk) another problem will show up then with the different prototypes of
    void boot_pwiz_swigbindings(PerlInterpreter*, int*) in line 1531 and
    SWIGEXPORT void boot_pwiz_swigbindings (pTHXo_ struct cv* cv) from line 1554.

    The type of the second parameter int * is incompatible to struct cv*. (The number of parameters seems to be right). It looks like SWIG did not generate this correctly with the supplied template. Maybe the template needs to be updated (line 1531 looks wrong). Anyhow, without access to the complete template and generated file it is quite difficult to guess how this could be rectified.