elbichon | 1 Jul 2009 17:17
Picon

Problem to wrap a C++ template for Python

I have a problem to wrap c++ templates!
This problem occur when the code to wrap is composed by a cpp and a hpp files (I have no problem with only a cpp).
swig and g++ compilation are well but when I import the module in python :

ImportError: ./_Stack.so: undefined symbol: _ZN5StackIiE3popEv

Can you help me? I have join my code to this mail.

Thx

p.s. : sorry for my bad english

Attachment (stack.tbz): application/x-bzip-compressed-tar, 16 KiB
------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
William S Fulton | 1 Jul 2009 23:05
Picon
Favicon
Gravatar

Re: namespace alias in C++ to C#

tlackey <at> sfmidaho.com wrote:
> I am new to using swig and I am having a problem accessing a class in an
> aliased namespace correctly.
> 
> the header file:
> 
> namespace bar=foo;
> 
> namespace foo {
>    class Handle
>      public:
>       ....
>    };
> }
> 
> swig file:
> 
> 
> class Handle
>     public:
>       ....
> };
> 
> When the swig wrapper is created  the code is like:
> 
> bar::Handle;
> 
> and it creates a generic swig pointer for it:
> SWIGTYPE_p_bar_Handle
> 
> It also creates the C# proxy class for the generic pointer
> SWIGTYPE_p_bar_Handle.cs and the Handle.cs class.
> 
> How do I get the generic swig pointer and the Handle to be the same?
> 
Give SWIG valid C++ code that will compile with a C++ compiler, for example:

%inline %{

namespace foo {
    class Handle {
      public:
//      ....
    };
}
namespace bar=foo;
void func(bar::Handle) {}

%}

William

------------------------------------------------------------------------------
Solomon Gibbs | 1 Jul 2009 23:12
Picon

Re: Change in handling of nested structs from 1.3.36?



On Mon, Jun 29, 2009 at 5:58 PM, William S Fulton <wsf <at> fultondesigns.co.uk> wrote:


2009/6/29 Solomon Gibbs <solomon.gibbs <at> gmail.com>



On Fri, Jun 26, 2009 at 7:20 PM, William S Fulton <wsf <at> fultondesigns.co.uk> wrote:


2009/6/26 Solomon Gibbs <solomon.gibbs <at> gmail.com>

On Thu, Jun 25, 2009 at 1:59 PM, William S Fulton <wsf <at> fultondesigns.co.uk> wrote:
Solomon Gibbs wrote:
I have a rather nasty struct in the code I'm wrapping. Though version 1.3.36, swig has always consumed it without complaining. However, I recently downloaded 1.3.39 and now I get a syntax error at the line corresponding to the end of the "meta_size" struct (below). The preprocess result from running swig with -E looks like more or less what I would expect.

Does anyone have any idea what has changed, or how to figure out I am doing wrong? I've tried a couple of the --debug-* options, but the parse seems to stop before they can have any effect.

Any help would be appreciated.

The following struct doesn't seem to work under 1.3.38 or 1.3.39. I haven't checked 1.3.37.

typedef struct H5O_info_t {
   unsigned long     fileno;
   haddr_t         addr;
   H5O_type_t         type;
   unsigned         rc;
   time_t        atime;
   time_t        mtime;
   time_t        ctime;
   time_t        btime;
   hsize_t         num_attrs;
   struct {
       unsigned version;
       unsigned nmesgs;
       unsigned nchunks;
       unsigned flags;
       struct {
           hsize_t total;
           hsize_t meta;
           hsize_t mesg;
           hsize_t free;
       } space;
       struct {
           uint64_t present;
           uint64_t shared;
       } mesg;
   } hdr;
   struct {
       H5_ih_info_t obj;
       H5_ih_info_t attr;
   } meta_size;
} H5O_info_t;

I don't get any error using this struct and I don't see any problems using valgrind on SWIG for this struct. I think the best thing is for you to provide the exact commandline options you are passing to SWIG and provide a complete standalone interface file that shows the problem. Also which operating system, compiler and compile options you used to compile SWIG.

William

The minimum module that causes the problem seems to be the struct itself. (attached, for completeness)

My swig commandline is:
/c/opt/swig/swigwin-1.3.39/swig.exe -java -package "permafrost.hdf.libhdf" -outdir "target/swig-java/permafrost/hdf/libhdf"  src/swig/H5O_info_t.i
src\swig\H5O_info_t.i(34): Error: Syntax error in input(3).

I am using the pre-build windows binaries from sourceforge; unzipped and used as-provided. But I have reason to suspect my install is misconfigured somehow anyway: If I try to run swig with -Wallkw, it fails while trying to load php.swg:

 /c/opt/swig/swigwin-1.3.39/swig.exe  -Wallkw  -java -package "permafrost.hdf.libhdf" -outdir "target/swig-java/permafrost/hdf/libhdf"  src/swig/H5O_info_t.i
c:\opt\swig\swigwin-1.3.39\Lib\php\php.swg(13): Error: Unable to find 'phpinit.swg'
c:\opt\swig\swigwin-1.3.39\Lib\php\php.swg(15): Error: Unable to find 'globalvar.i'
c:\opt\swig\swigwin-1.3.39\Lib\php\php.swg(16): Error: Unable to find 'const.i'
c:\opt\swig\swigwin-1.3.39\Lib\php\php.swg(38): Error: Unable to find 'utils.i'
c:\opt\swig\swigwin-1.3.39\Lib\php\php.swg(311): Error: Unable to find 'phpkw.swg'
 

Can you check that the Java examples work unmodified in the Examples\Java\class directory. There is a visual studio project in this directory for you to run and build everything (use Release build). Have you tried downloading the swigwin package again?

William

I ran the example you suggested. I did need to set the project environment variables for JAVA_INCLUDE and JAVA_BIN. Once those were set, everything worked okay.

I've downloaded swigwin-1.3.39 twice as well as 1.3.37 and 1.3.38. None of the last three releases appear to work on my interface. They each give the same syntax error processing the struct and they all fail trying to load the php-related files with launched with -Wallkw.

I have also tried re-downloading 1.3.36 and unzipping it in a new directory to try and rule out some sort of path issue. 1.3.36 seems to work no matter where I install it. It also accepts -Wallkw properly.
This smells like an installation/path problem. Do you simply unzip the swigwin zip file and run swig from there? Check that the library is configured correctly, like this:

C:\swig\swigwin-1.3.39>cd Examples\java\simple

C:\swig\swigwin-1.3.39\Examples\java\simple>..\..\..\swig.exe -swiglib
C:\swig\swigwin-1.3.39\Lib

Then run the example in verbose mode and check the search paths are as below:

C:\swig\swigwin-1.3.39\Examples\java\simple>..\..\..\swig.exe -v -java example.i

LangSubDir: java
Search paths:
   .\
   .\swig_lib\java\
   C:\swig\swigwin-1.3.39\Lib\java\
   \java\
   .\swig_lib\
   C:\swig\swigwin-1.3.39\Lib\
   \
Preprocessing...
Starting language-specific parse...
Processing types...
C++ analysis...
Generating wrappers...

If all that is the same then in modify example.i demonstrating the problem using the same command line options and send the example.i here.

William

I now know what is causing the syntax error. In retrospect, I shouldn't have removed the comments from the module when I posted it earlier. The real module contains the doxygen end-of-line comment:
/**< v1/v2 B-tree & local/fractal heap for groups, B-tree for chunked datasets */

It appears that the '/' characters in the comment cause the syntax error. If I delete them, the problem goes away.

The module with the problematic comment is attached.

I'm still not sure why -Wallkw fails because the swig search paths are just as you described them, but I'm prepared to live without it.

Thanks for all the help and sorry to have muddled the problem by sending the incomplete code.
Attachment (example.i): application/octet-stream, 815 bytes
------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
lacktrum | 2 Jul 2009 01:26
Favicon

Re: namespace alias in C++ to C#


tlackey wrote:
> 
> I am new to using swig and I am having a problem accessing a class in an
> aliased namespace correctly.
> 
> the header file:
> 
> namespace bar=foo;
> 
> namespace foo {
>    class Handle
>      public:
>       ....
>    };
> }
> 
> swig file:
> 
> 
> class Handle
>     public:
>       ....
> };
> 
> When the swig wrapper is created  the code is like:
> 
> bar::Handle;
> 
> and it creates a generic swig pointer for it:
> SWIGTYPE_p_bar_Handle
> 
> It also creates the C# proxy class for the generic pointer
> SWIGTYPE_p_bar_Handle.cs and the Handle.cs class.
> 
> How do I get the generic swig pointer and the Handle to be the same?
> 
> Thanks,
> 
> Truman Lackey
> 
> 
> 
> ------------------------------------------------------------------------------
> _______________________________________________
> Swig-user mailing list
> Swig-user <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/swig-user
> 
> 

To answer my own question I placed the following in my .i file:

namespace foo {
   class Handle
     public:
      ....
   };
}

class Handle
    public:
      ....
};

This handles both namespaced references to Handle and non namespace
references.
Is there possible a more elegant way to resolve this?  

As it is right now I have a lot of class code replication in my SWIG file.

--

-- 
View this message in context: http://www.nabble.com/namespace-alias-in-C%2B%2B-to-C--tp24280964p24294672.html
Sent from the swig-user mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Ricky Marek | 2 Jul 2009 16:29
Favicon

[Q] Howto Send/Return "unsigned char" arrays between "C" and "Perl5" Swig?

Hello,

I'm new to SWIG.

The Scenario:  I have some code that needs to interface with a low level driver that will receive or
send buffers through some hardware device (I2C in my case), and be able to run it from a Perl script.
Running native "C" code allows me to do all the required operations, but I'm required to run the same
from Perl.

The 'C' functions I want to be wrapped (and be visible to Perl) have the following signature:

	int i2c_write(I2C_HANDLE *handle, int count, unsigned char *input_buffer);
	int i2c_read(I2C_HANDLE *handle,  int count, unsigned char *output_buffer);

Both the input and output buffers will contain binary data (not strings) and are pointers to an array, 
previously allocated with enough room to work.

As far I have seen with SWIG is that "char *" (or/and unsigned "char *") is dealt in a special way 
that can be used as an array...

The interface from Perl that I expect is that I will prepare an Perl array containing the characters
to be sent, or receive an array with the characters received. Is this possible?

	 <at> buffer = ( 10, 255, 23, 12, 70, 1 .. 255);
	$count = I2C::write($handle,  <at> buffer);
	...
	$count = I2C::read($handle,  <at> buffer);

	foreach $i ( <at> buffer(
	{
		print "Got $i\n";
	}

Also the use of "pack" or "unpack" is acceptable.

Currently I'm using a "carrays.i" for this task, which adds a lot of overhead on the perl scripts.. 
and also a small warning on the manual tells me not to use "char *" with "%array_functions" 
(end of section 8.2.2) 

[Q] Is it safe to use "%array_functions" with "unsigned char *"?

Thanks in advance

--- Ricky Marek.

------------------------------------------------------------------------------
Ricky Marek | 2 Jul 2009 15:14
Favicon

[Q] Howto Send/Return "unsigned char" arrays between "C" and "Perl5" Swig?

Hello,

I'm new to SWIG.

The Scenario:  I have some code that needs to interface with a low level driver that will receive or
send buffers through some hardware device (I2C in my case), and be able to run it from a Perl script.
Running native "C" code allows me to do all the required operations, but I'm required to run the same
from Perl.

The 'C' functions I want to be wrapped (and be visible to Perl) have the following signature:

	int i2c_write(I2C_HANDLE *handle, int count, unsigned char *input_buffer);
	int i2c_read(I2C_HANDLE *handle,  int count, unsigned char *output_buffer);

Both the input and output buffers will contain binary data (not strings) and are pointers to an array, 
previously allocated with enough room to work.

As far I have seen with SWIG is that "char *" (or/and unsigned "char *") is dealt in a special way 
that can be used as an array...

The interface from Perl that I expect is that I will prepare an Perl array containing the characters
to be sent, or receive an array with the characters received. Is this possible?

	 <at> buffer = ( 10, 255, 23, 12, 70, 1 .. 255);
	$count = I2C::write($handle,  <at> buffer);
	...
	$count = I2C::read($handle,  <at> buffer);

	foreach $i ( <at> buffer(
	{
		print "Got $i\n";
	}

Also the use of "pack" or "unpack" is acceptable.

Currently I'm using a "carrays.i" for this task, which adds a lot of overhead on the perl scripts.. 
and also a small warning on the manual tells me not to use "char *" with "%array_functions" 
(end of section 8.2.2) 

[Q] Is it safe to use "%array_functions" with "unsigned char *"?

Thanks in advance

--- Ricky Marek.

------------------------------------------------------------------------------
David Piepgrass | 2 Jul 2009 18:36
Favicon

Re: namespace alias in C++ to C#

> To answer my own question I placed the following in my .i file:
> 
> namespace foo {
>    class Handle
>      public:
>       ....
>    };
> }
> 
> class Handle
>     public:
>       ....
> };
> 
> This handles both namespaced references to Handle and non namespace
> references.
> Is there possible a more elegant way to resolve this?

Might I suggest:

namespace foo {
   class Handle
     public:
      ....
   };
}
typedef foo::Handle Handle;

------------------------------------------------------------------------------
William S Fulton | 2 Jul 2009 20:29
Picon
Favicon
Gravatar

Re: Change in handling of nested structs from 1.3.36?

Solomon Gibbs wrote:

> I now know what is causing the syntax error. In retrospect, I shouldn't 
> have removed the comments from the module when I posted it earlier. The 
> real module contains the doxygen end-of-line comment:
> /**≤ v1/v2 B-tree & local/fractal heap for groups, B-tree for chunked 
> datasets */
> 
> It appears that the '/' characters in the comment cause the syntax 
> error. If I delete them, the problem goes away.
> 
> The module with the problematic comment is attached.
> 
This is a regression from 1.3.37, now fixed in svn.

> I'm still not sure why -Wallkw fails because the swig search paths are 
> just as you described them, but I'm prepared to live without it.
> 
Also just fixed in svn.

William

------------------------------------------------------------------------------
William S Fulton | 2 Jul 2009 20:30
Picon
Favicon
Gravatar

Re: namespace alias in C++ to C#

lacktrum wrote:
> 
> tlackey wrote:
>> I am new to using swig and I am having a problem accessing a class in an
>> aliased namespace correctly.
>>
>> the header file:
>>
>> namespace bar=foo;
>>
>> namespace foo {
>>    class Handle
>>      public:
>>       ....
>>    };
>> }
>>
>> swig file:
>>
>>
>> class Handle
>>     public:
>>       ....
>> };
>>
>> When the swig wrapper is created  the code is like:
>>
>> bar::Handle;
>>
>> and it creates a generic swig pointer for it:
>> SWIGTYPE_p_bar_Handle
>>
>> It also creates the C# proxy class for the generic pointer
>> SWIGTYPE_p_bar_Handle.cs and the Handle.cs class.
>>
>> How do I get the generic swig pointer and the Handle to be the same?
>>
>> Thanks,
>>
>> Truman Lackey
>>
>>
>>
>> ------------------------------------------------------------------------------
>> _______________________________________________
>> Swig-user mailing list
>> Swig-user <at> lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/swig-user
>>
>>
> 
> To answer my own question I placed the following in my .i file:
> 
> namespace foo {
>    class Handle
>      public:
>       ....
>    };
> }
> 
> class Handle
>     public:
>       ....
> };
> 
> This handles both namespaced references to Handle and non namespace
> references.
> Is there possible a more elegant way to resolve this?  
> 
> As it is right now I have a lot of class code replication in my SWIG file.
> 
Did you see my reply? If you give SWIG the correct C++ code it should do 
the right thing. You can do this by replicating the classes *exactly* in 
your interface file or more simply use %include of the original headers.

William

------------------------------------------------------------------------------
soulos | 3 Jul 2009 03:01
Picon

Swig, C++, Python and pyodbc


G'day Guys,
I've got swig building creating the linkage between python and c++ so that I
can create objects in either language that the other can use, which is
great!.  However when I try and do:
import sys
import mySwigComponent
import pyodbc

it fails, and tells me there is no module named pyodbc.  I've ensured that
the pyodbc.pyd file is in the correct path, I've even tried sys.path.append(
) to ensure that the location is know, to no avail.

I am currently using Python 2.6.2 with the pyodbc.pyd built against it.

Hope someone can help, I'm pulling my hair out and I'm sure it's something
simple that I've missed.

Cheers

--

-- 
View this message in context: http://www.nabble.com/Swig%2C-C%2B%2B%2C-Python-and-pyodbc-tp24285918p24285918.html
Sent from the swig-user mailing list archive at Nabble.com.

------------------------------------------------------------------------------

Gmane