Problem using SWIG with perl

N

None

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.
 
V

Victor Bazarov

None said:
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
 
A

Avi

It seems that some macro replaces "NORMAL" with "PL_op->op_next". I
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.
 
V

Victor Bazarov

Avi said:
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
 
A

Avi

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.
 
J

Jim Langston

Avi said:
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.
 
D

David Harmon

On Thu, 11 Jan 2007 15:43:34 -0500 in comp.lang.c++, "Victor Bazarov"
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top