Problem using SWIG with perl

Discussion in 'C++' started by None, Jan 11, 2007.

  1. None

    None Guest

    Hi,

    I was trying to use SWIG to expose some C++ functions to perl. But, I
    ran into some issues here. I don't know why, but I see that a macro in
    SWIG replaces "NORMAL" with "PL_op->op_next"...

    I ran the following test:

    Files:

    test.cxx:
    #include "test.h"

    test.h:
    enum User
    {
    NORMAL = 1,
    FOREIGN = 2
    };

    test.i:

    /* File : test.i */
    %module test

    %{
    #include "test.h"
    %}

    /* Let's just grab the original header file here */

    %include "test.h"

    If I run the Makefile (similar to the one in Examples/Perl5 directory
    in SWIG), it gives the following error :

    In file included from test_wrap.cxx:1464:
    test.h:5: error: `PL_op' redeclared as different kind of symbol
    /prj/qisdcrm/QChat/perl-5.6.1-Linux/lib/5.6.1/i686-linux/CORE/thrdvar.h:25:
    error: previous declaration of `OP*PL_op'
    test.h:5: error: declaration of `PL_op'
    /prj/qisdcrm/QChat/perl-5.6.1-Linux/lib/5.6.1/i686-linux/CORE/thrdvar.h:25:
    error: conflicts with previous declaration `OP*PL_op'
    test.h:5: error: expected `}' before '->' token
    test.h:5: error: expected unqualified-id before '->' token
    test.h:8: error: expected declaration before '}' token
    make[1]: *** [perl5_cpp] Error 1


    It seems that some macro replaces "NORMAL" with "PL_op->op_next". I ran
    a "grep" for "NORMAL" in the SWIG directory, but could not find
    anything that replaces it. Can anyone help me with this?

    Thanks,
    Avinash.
     
    None, Jan 11, 2007
    #1
    1. Advertising

  2. None wrote:
    > I was trying to use SWIG to expose some C++ functions to perl. But, I
    > ran into some issues here. I don't know why, but I see that a macro in
    > SWIG replaces "NORMAL" with "PL_op->op_next"...
    >

    [..]
    >
    > It seems that some macro replaces "NORMAL" with "PL_op->op_next". I
    > ran a "grep" for "NORMAL" in the SWIG directory, but could not find
    > anything that replaces it. Can anyone help me with this?


    Look further. Look in your compiler's 'include' directory, in your
    OS headers, in other libraries, in your own headers...

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Jan 11, 2007
    #2
    1. Advertising

  3. None

    Avi Guest

    > > It seems that some macro replaces "NORMAL" with "PL_op->op_next". I
    > > ran a "grep" for "NORMAL" in the SWIG directory, but could not find
    > > anything that replaces it. Can anyone help me with this?

    >
    > Look further. Look in your compiler's 'include' directory, in your
    > OS headers, in other libraries, in your own headers...
    >



    I just replaced "NORMAL" with "NORMAL_TYPE" and it works fine. Also, I
    tried removing NORMAL from theenum and declaring :
    #define NORMAL 1

    It works fine. Is there a problem with declaring NORMAL within an enum
    only? This is really wierd!

    -Avinash.
     
    Avi, Jan 11, 2007
    #3
  4. Avi wrote:
    >>> It seems that some macro replaces "NORMAL" with "PL_op->op_next". I
    >>> ran a "grep" for "NORMAL" in the SWIG directory, but could not find
    >>> anything that replaces it. Can anyone help me with this?

    >>
    >> Look further. Look in your compiler's 'include' directory, in your
    >> OS headers, in other libraries, in your own headers...
    >>

    >
    >
    > I just replaced "NORMAL" with "NORMAL_TYPE" and it works fine. Also, I
    > tried removing NORMAL from theenum and declaring :
    > #define NORMAL 1
    >
    > It works fine. Is there a problem with declaring NORMAL within an enum
    > only? This is really wierd!


    If 'NORMAL' is a macro (which it looks like, from your original post),
    then redefining it should cause a good compiler to complain. Turn up
    your warning level to the max, see if you get "redefinition" warning
    with a reference to the place where 'NORMAL' is previously defined...

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Jan 11, 2007
    #4
  5. None

    Avi Guest

    > If 'NORMAL' is a macro (which it looks like, from your original post),
    > then redefining it should cause a good compiler to complain. Turn up
    > your warning level to the max, see if you get "redefinition" warning
    > with a reference to the place where 'NORMAL' is previously defined...
    >



    Yes I got the problem fixed. I tried undefining the macro while
    compiling. That did not work. But with some help from the forums, I got
    to know that I had to add the following code snippet in the .i file:

    %runtime %{
    #undef NORMAL
    %}

    Basically undefine the macro in the runtime environment.
    This seems to work fine. Thanks a lot for the help.

    -Avi.
     
    Avi, Jan 11, 2007
    #5
  6. None

    Jim Langston Guest

    "Avi" <> wrote in message
    news:...
    >> If 'NORMAL' is a macro (which it looks like, from your original post),
    >> then redefining it should cause a good compiler to complain. Turn up
    >> your warning level to the max, see if you get "redefinition" warning
    >> with a reference to the place where 'NORMAL' is previously defined...
    >>

    >
    >
    > Yes I got the problem fixed. I tried undefining the macro while
    > compiling. That did not work. But with some help from the forums, I got
    > to know that I had to add the following code snippet in the .i file:
    >
    > %runtime %{
    > #undef NORMAL
    > %}
    >
    > Basically undefine the macro in the runtime environment.
    > This seems to work fine. Thanks a lot for the help.


    Your other option would be to follow the advice that says only macros use
    all capital letters. Since your enum of NORMAL isn't a macro, it should be
    Normal or something else. Then you wouldn't have to undefine anything
    because your variable name wouldn't be conflicting with your macro name.
     
    Jim Langston, Jan 11, 2007
    #6
  7. None

    David Harmon Guest

    On Thu, 11 Jan 2007 15:43:34 -0500 in comp.lang.c++, "Victor Bazarov"
    <> wrote,
    >If 'NORMAL' is a macro (which it looks like, from your original post),
    >then redefining it should cause a good compiler to complain. Turn up
    >your warning level to the max, see if you get "redefinition" warning
    >with a reference to the place where 'NORMAL' is previously defined...


    Or if that doesn't tell where it's coming from, put a line like

    #define NORMAL ::::

    before the first include, and see what the error message changes to.
     
    David Harmon, Jan 12, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alfonso Cepeda Caballos,,,

    Problem using swig

    Alfonso Cepeda Caballos,,,, Nov 4, 2003, in forum: Python
    Replies:
    0
    Views:
    307
    Alfonso Cepeda Caballos,,,
    Nov 4, 2003
  2. stefan
    Replies:
    3
    Views:
    451
    stefan
    Dec 8, 2004
  3. Replies:
    2
    Views:
    205
  4. Sandeep Kumar

    Problem using SWIG approach

    Sandeep Kumar, Apr 14, 2006, in forum: Perl Misc
    Replies:
    0
    Views:
    108
    Sandeep Kumar
    Apr 14, 2006
  5. None

    Problem using SWIG with perl

    None, Jan 11, 2007, in forum: Perl Misc
    Replies:
    0
    Views:
    95
Loading...

Share This Page