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

Re^3: SWIG and conflicting definitions

by hexcoder (Curate)
on Jan 08, 2016 at 11:16 UTC ( [id://1152294]=note: print w/replies, xml ) Need Help??


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

My error, sorry. I should have said to put the line

#define CV __perl_CV

before this one

#include "perl.h"

otherwise it looks ok.

Update: some explanations added

What I intend to do, is this:

  1. for the processing of perl.h, XSUB.h and the included header files therein, substitute the offending identifier CV by __perl_CV. This is done by the preprocessor directive #define CV __perl_CV
  2. Afterwards redeclare the macro XSPROTO, which was using CV also. Unfortunately the above substitution affects only C code, but not subsequent preprocessor directives, so we need to adjust this macro definition.
    This is done by first deleting the old macro definition (#undef XSPROTO), and then by defining it again, but this time with __perl_CV instead of CV.
  3. Finally delete the substitution for identifier CV (#undef CV, so that the following code can use it exclusively.
  4. This in total should remove the conflict between the two different definitions of CV by using __perl_CV for the first one instead.

If you are curious, you can look at the difference of the preprocessed outputs with and without the modification (gcc -E -dDfile should produce them).

Replies are listed 'Best First'.
Re^4: SWIG and conflicting definitions
by jdv (Sexton) on Jan 08, 2016 at 15:01 UTC

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

    Here is the context refered to in the first line:

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

      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.

      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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-20 03:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found