Christophe Dupre | 1 Apr 2009 10:51

Python 2.6 and Visual Studio 2005

Hello,

 

I've installed SWIG 1.3.39, and I'm trying to compile python 2.6 modules using Visual Studio 2005.

I can compile the "simple" python example provided but I cannot link it, and get the following error:

1>Compiling...

1>example_wrap.c

1>example.c

1>Generating Code...

1>Linking...

1>LINK : fatal error LNK1181: cannot open input file 'c:\python26\include.obj'

 

 

I'm not sure why the linker needs that file. The file is definitely not present.

 

Thanks,

 

Christophe

 

------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
William S Fulton | 1 Apr 2009 13:08
Picon
Favicon
Gravatar

Re: Python 2.6 and Visual Studio 2005

Christophe Dupre wrote:
> Hello,
> 
>  
> 
> I've installed SWIG 1.3.39, and I'm trying to compile python 2.6 modules 
> using Visual Studio 2005.
> 
> I can compile the "simple" python example provided but I cannot link it, 
> and get the following error:
> 
> 1>Compiling...
> 
> 1>example_wrap.c
> 
> 1>example.c
> 
> 1>Generating Code...
> 
> 1>Linking...
> 
> 1>LINK : fatal error LNK1181: cannot open input file 
> 'c:\python26\include.obj'
> 
>  
> 
>  
> 
> I'm not sure why the linker needs that file. The file is definitely not 
> present.
> 
>  

I tried with Python 2.6.1 and Visual Studio 2008 and it all works. Here 
is the output for you to compare against (note using the release build 
and the environment variables are set as documented in 
http://www.swig.org/Doc1.3/Windows.html#Windows_examples):

1>------ Build started: Project: example, Configuration: Release Win32 
------
1>Performing Custom Build Step
1>In order to function correctly, please ensure the following 
environment variables are correctly set:
1>PYTHON_INCLUDE: C:\Python26\Include
1>PYTHON_LIB: C:\Python26\libs\python26.lib
1>C:\swig\swigwin-1.3.39\Examples\python\simple>..\..\..\swig.exe 
-python C:\swig\swigwin-1.3.39\Examples\python\simple\example.i
1>C:\swig\swigwin-1.3.39\Examples\python\simple>if errorlevel 1 goto 
VCReportError
1>C:\swig\swigwin-1.3.39\Examples\python\simple>goto VCEnd
1>Compiling...
1>example_wrap.c
1>example.c
1>Generating Code...
1>Linking...
1>   Creating library .\Release/_example.lib and object 
.\Release/_example.exp
1>Embedding manifest...
1>Build log was saved at 
"file://C:\swig\swigwin-1.3.39\Examples\python\simple\Release\BuildLog.htm"
1>example - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

Are you using 2.6.0 or 2.6.1?

William

------------------------------------------------------------------------------
amit sethi | 1 Apr 2009 13:50
Picon

Re: gsoc idea mapping source language comments to target language.

Sorry for the late reply . I would love to work on documentation work but i also like this as an opportunity to code .So I have submitted a proposal for this and awaiting your comments.

On Mon, Mar 30, 2009 at 10:23 PM, William S Fulton <wsf <at> fultondesigns.co.uk> wrote:
amit sethi wrote:
The project would be an extension to last years work for Java.
My work would be in writing modules similar to Java conversion modules written last year
Since the modules for catching comments in source language have been developed already my work would be to only or
write translators only .
I would like to do this for atlease target languages -> Python and PHP.
But i wish to add ruby and perl if time allows.
I have experience of developing on both these languages . I develop majorly python  and have found swig to be an important part of Developmnent cycle . I do not have much development experince in C++ (i have learnt it in school though) but I am willing to learn  for the sake of this project as it improves the development enviroment for python and php developers.
--
Amit, it will be great to get the documentation project completed. I suggest you browse the work that has already been completed at http://swig.svn.sourceforge.net/viewvc/swig/branches/gsoc2008-cherylfoil and the documentation currently available on this at http://swig.svn.sourceforge.net/viewvc/swig/branches/gsoc2008-cherylfoil/Doc/Manual/Doxygen.html.  If you have any queries, chat on our #swig-gsoc IRC channel.

William



--
A-M-I-T S|S
------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Christophe Dupre | 1 Apr 2009 14:06

Re: Python 2.6 and Visual Studio 2005


> -----Original Message-----
> From: William Fulton [mailto:william <at> fultondesigns.co.uk] On Behalf Of
William S Fulton
> Sent: 01 April 2009 12:08
> To: Christophe Dupre
> Cc: swig-user <at> lists.sourceforge.net
> Subject: Re: [Swig-user] Python 2.6 and Visual Studio 2005
>
> Christophe Dupre wrote:
> > Hello,
> > 
> >  
> > 
> > I've installed SWIG 1.3.39, and I'm trying to compile python 2.6
modules 
v> using Visual Studio 2005.
> > 
> > I can compile the "simple" python example provided but I cannot link
it, 
> > and get the following error:
> > 
> > 1>Compiling...
> > 
> > 1>example_wrap.c
> > 
> > 1>example.c
> > 
> > 1>Generating Code...
> > 
> > 1>Linking...
> > 
> > 1>LINK : fatal error LNK1181: cannot open input file 
> > 'c:\python26\include.obj'
> > 
> >  
> > 
> >  
> > 
> > I'm not sure why the linker needs that file. The file is definitely
not 
> > present.
> > 
> >  
>
> I tried with Python 2.6.1 and Visual Studio 2008 and it all works.
Here 
> is the output for you to compare against (note using the release build

> and the environment variables are set as documented in 
> http://www.swig.org/Doc1.3/Windows.html#Windows_examples):
>
> 1>------ Build started: Project: example, Configuration: Release Win32

> ------
> 1>Performing Custom Build Step
> 1>In order to function correctly, please ensure the following 
> environment variables are correctly set:
> 1>PYTHON_INCLUDE: C:\Python26\Include
> 1>PYTHON_LIB: C:\Python26\libs\python26.lib
> 1>C:\swig\swigwin-1.3.39\Examples\python\simple>..\..\..\swig.exe 
> -python C:\swig\swigwin-1.3.39\Examples\python\simple\example.i
> 1>C:\swig\swigwin-1.3.39\Examples\python\simple>if errorlevel 1 goto 
> VCReportError
> 1>C:\swig\swigwin-1.3.39\Examples\python\simple>goto VCEnd
> 1>Compiling...
> 1>example_wrap.c
> 1>example.c
> 1>Generating Code...
> 1>Linking...
> 1>   Creating library .\Release/_example.lib and object 
>.\Release/_example.exp
> 1>Embedding manifest...
> 1>Build log was saved at 
>
"file://C:\swig\swigwin-1.3.39\Examples\python\simple\Release\BuildLog.h
tm"
> 1>example - 0 error(s), 0 warning(s)
> ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped
==========
>
> Are you using 2.6.0 or 2.6.1?
>
> William

Thanks for the help.
I'm using python 2.6.1.
I indeed had my environment variables wrong. I can now compile and link
the "class" example, but I cannot link the "simple" example. Here is the
output:

1>------ Rebuild All started: Project: example, Configuration: Release
Win32 ------
1>Deleting intermediate and output files for project 'example',
configuration 'Release|Win32'
1>Performing Custom Build Step
1>In order to function correctly, please ensure the following
environment variables are correctly set:
1>PYTHON_INCLUDE: c:\python26\include
1>PYTHON_LIB: c:\python26\libs\python26.lib
1>c:\Python26\swig\Examples\python\simple>..\..\..\swig.exe -python
c:\Python26\swig\Examples\python\simple\example.i 
1>c:\Python26\swig\Examples\python\simple>if errorlevel 1 goto
VCReportError 
1>c:\Python26\swig\Examples\python\simple>goto VCEnd 
1>Compiling...
1>example_wrap.c
1>example.c
1>Generating Code...
1>Linking...
1>   Creating library .\Release/_example.lib and object
.\Release/_example.exp
1>LIBCMT.lib(crt0.obj) : error LNK2019: unresolved external symbol _main
referenced in function ___tmainCRTStartup
1>_example.pyd : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at
"file://c:\Python26\swig\Examples\python\simple\Release\BuildLog.htm"
1>example - 2 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Christophe

------------------------------------------------------------------------------
William S Fulton | 1 Apr 2009 23:46
Picon
Favicon
Gravatar

Re: C# - generic wrappers for std::vector<T>

David Piepgrass wrote:
>> I've made changes to implement IEnumerable<> rather than IList<> as
>> IList<> ultimately requires the C++ operator== to be available, which it
>> often isn't. 
> 
> You can already put SWIG wrappers in List<T> objects, so it's kind of disingenuous to imply IList<T> can't
be supported. And List<T> doesn't use operator==, which is a statically bound call and therefore not
callable from generic classes. Instead it uses EqualityComparer<T>.Default, I believe, which must use Equals().
> 
> The most important features of IList<T> such as Add, Remove, Clear, and this[index] do not use an equality
test, so I strongly encourage you to reconsider.
But in order to implement an interface, all the methods must be
implemented. IList<T> requires the IndexOf and Contains methods, which
in turn require the C++ std::find, which in turn requires a C++
operator==. This is because we are using value equality, not reference
equality, see my comments at the end. Basically I don't won't to put in 
dependencies that will result in non-compileable code most of the time.

Note that although, the wrappers don't implement IList<>, they do
implement most of the methods that IList<> requires. The ones omitted
are the ones that rely on equality.

> 
> Besides, any SWIG user could (and IMO, should) override Equals(object) and operator==() as I have done.
My approach is something like this, except altered to be Compact Framework compatible:
> 
> %typemap(csclassmodifiers) SWIGTYPE "public partial class"
> %typemap(csclassmodifiers) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "public partial struct"
> 
> ////////////////////////////////////////////////////////////////////////////
> // Implement Equals() and GetHashCode() on all wrapper classes.  The same C++ 
> // object may be represented by multiple instances of the proxy class, so we 
> // need to change these functions so that two different instances of the proxy 
> // class that point to the same C++ object are considered equal and have the 
> // same hash code. At the same time, improve code sharing by putting these 
> // functions, getCPtr() and swigCPtr in a common base class.
> //
> // Put Equals() and GetHashCode() in a base class ("CppWrapper") so that they 
> // can be replaced, if desired, in a derived class.
> %pragma(csharp) imclassimports=%{
> using System;
> using System.Runtime.InteropServices;
> using System.Drawing;
> 
> public class CppWrapper 
> {
>   protected HandleRef swigCPtr;
> 
>   public CppWrapper(IntPtr cPtr)
> 	{ swigCPtr = new HandleRef(this, cPtr); }
> 
>   protected internal static IntPtr getCPtr(CppWrapper obj) {
>     return object.ReferenceEquals(obj, null) ? IntPtr.Zero : (IntPtr)obj.swigCPtr;
>   }
>   public override bool Equals(object other_) {
>     CppWrapper other = other_ as CppWrapper;
>     return getCPtr(other) == swigCPtr;
>   }
This implementation of Equals needs modifying to meet the conditions as
stated in the Object.Equals documentation -
http://msdn.microsoft.com/en-us/library/bsc2ak47(VS.80).aspx and
"Guidelines for Overloading Equals() and Operator == (C# Programming
Guide)" - http://msdn.microsoft.com/en-us/library/ms173147(VS.80).aspx.

>   public override int GetHashCode() {
>     return swigCPtr.ToInt32();
>   }
XOR high and low bits as suggested in the Object.GetHashCode docs would
be better -
http://msdn.microsoft.com/en-us/library/system.object.gethashcode(VS.80).aspx 

(for 64 bit pointers).

>   public static bool operator!=(CppWrapper a, CppWrapper b)
>     { return getCPtr(a) != getCPtr(b); }
>   public static bool operator==(CppWrapper a, CppWrapper b) 
>     { return getCPtr(a) == getCPtr(b); }
> }
> %}
> %typemap(csbase) SWIGTYPE "CppWrapper"
Having a single swigCPtr in the inheritance hierarchy is dangerous, see
comments below.

> %typemap(csbase) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
> // SWIG gives this absurd warning for derived classes: "Warning for 
> // DerivedClass proxy: Base CppWrapper ignored. Multiple inheritance is not 
> // supported in C#." Workaround: suppress that warning universally
> %warnfilter(SWIGWARN_CSHARP_MULTIPLE_INHERITANCE);
Didn't we fix this by providing the 'replace' attribute - Bug #1794247?
If not, please lodge a new bug including a small use case. I've seen you
post your typemaps a few times which is great, but would prefer up to
date code if doing so again so as to not mislead future 'googlers'.

> // Normal wrappers (for defined types) use this code
> %typemap(csbody, noblock=1) SWIGTYPE 
> { //
>   protected bool swigCMemOwn;
>   protected internal $csclassname(IntPtr cPtr, bool cMemoryOwn) : base(cPtr) {
>     if (!(swigCMemOwn = cMemoryOwn))
> 		GC.SuppressFinalize(this);
>   }
This is a neat performance trick I've not seen before which I thought
might be useful for the default typemaps. But after some pondering I
think it is too risky to put into the default SWIG typemaps as it is
possible that some users customisations will set swigCMemOwn to true
after the constructor is called. I'd suggest making swigCMemOwn
readonly to future proof your code with a compilation error... once
you've done that I think you'll find that you could even get rid of the
swigCMemOwn flag altogether.

> }
> 
> // Wrappers for unknown types (e.g. SWIGTYPE_p_int) use this code
> %typemap(csbody, noblock=1) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] 
> { //
>   protected HandleRef swigCPtr;
>   internal $csclassname(IntPtr cPtr, bool futureUse) { swigCPtr = new HandleRef(this, cPtr); }
>   
>   internal static HandleRef getCPtr(CppWrapper obj) {
>     return (obj == null) ? IntPtr.Zero : obj.swigCPtr;
>   }
> }
> 
> // Derived proxy classes use this code
> // In my wrappers there is no reason to call back into C++ to do an upcast 
> // (and SWIG doesn't support multiple inheritance anyway), so I removed that 
> // code from here.
Could I ask you to add in a big DANGER sign in your comments here if
you are going to post this onto the internet again as you are relying on
behaviour that is not guaranteed in the C++ standard and is liable to
subtle, hard to track bugs, particularly so as you have suppressed
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE.

> %typemap(csbody_derived) SWIGTYPE %{
>   //private HandleRef swigCPtr;
> 
>   internal $csclassname(IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) { 
>     //  : base($imclassname.$csclassnameUpcast(cPtr), cMemoryOwn) {
>     //swigCPtr = new HandleRef(this, cPtr);
>   }
> 
>   //internal static HandleRef getCPtr($csclassname obj) {
>   //  return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
>   //}
> %}
> 
> -------------------------------------------------------------------
> 
>> Please try it out in the next day, just use the latest std_vector.i by
>> putting it in whichever version of SWIG you have. Get it from:
>> http://swig.svn.sourceforge.net/viewvc/swig/trunk/Lib/csharp/std_vector.i?
>> view=log
> 
> OK, I'll try to remember to try it. I can't try it until Monday though.
> 
>> Are you saying that the current enumerator implementation, which as you
>> say uses objects, can be improved performance-wise? Should we replace
>> storing as 'object' with the real collection type? It'll need a slight
>> rewrite though as casting null to primitive types (if collection type is
>> primitive) doesn't work.
> 
> Yes, you'll get higher performance using the real collection type, especially if the real collection
type is something simple like int. I think it's legal to use default(xyz) instead of null, e.g.
default(int) is 0 and default(string) is null.
Okay good news, but if default(int) will give 0, it is a valid value for 
int, which breaks the logic in the Current property (which is expecting
null), so a minor rewrite is needed.

The idea of overriding Equals and GetHashCode and overloading operator==
makes sense as it provides reference equals on the C++ instance level
rather than on C# instances and I'm thinking of putting this as a
default into SWIG. However, using a single base class implementation of
this is incorrect and instead I'd generate the methods into every proxy
class.

With regard to using the C++ operator==, the advice given in the MSDN 
links above says: "Consider overriding Equals on a reference type if the
semantics of the type are based on the fact that the type represents
some value(s)". Surely, if there is a C++ operator== the advice then
applies and we should be using value equality. If say we are wrapping
std::vector<T> where T is a class (not a pointer to a class), then using
reference equals is just plain wrong as we are storing the object by 
value, not reference/pointer. If we are wrapping
std::vector<T*> or std::vector<T&> then implementing reference equality 
makes sense and we could modify the specializations in std_vector.i to 
do this.

William

------------------------------------------------------------------------------
David Piepgrass | 3 Apr 2009 02:13
Favicon

Re: C# - generic wrappers for std::vector<T>

> >   public override int GetHashCode() {
> >     return swigCPtr.ToInt32();
> >   }
> XOR high and low bits as suggested in the Object.GetHashCode docs would
> be better -
> http://msdn.microsoft.com/en-us/library/system.object.gethashcode(VS.80).aspx
> 
> (for 64 bit pointers).

If Microsoft follows its own advice, you should be able to simply call swigCPtr.GetHashCode() and it would
hash the high and low words for you. But documentation of HandleRef.GetHashCode appears not to have been written.

I wouldn't worry about it, because I'll bet there isn't a lot of variation in the high-order 32 bits of a
64-bit pointer. Besides, aren't most people still using 32 bit processes?

> Having a single swigCPtr in the inheritance hierarchy is dangerous, see
> comments below.

Yeah, it's dangerous in general, I know, but it's safe for me personally because I don't use MI in code
wrapped by SWIG.

> > %typemap(csbase) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE
> (CLASS::*) ""
> > // SWIG gives this absurd warning for derived classes: "Warning for
> > // DerivedClass proxy: Base CppWrapper ignored. Multiple inheritance is
> not
> > // supported in C#." Workaround: suppress that warning universally
> > %warnfilter(SWIGWARN_CSHARP_MULTIPLE_INHERITANCE);
>
> Didn't we fix this by providing the 'replace' attribute - Bug #1794247?
> If not, please lodge a new bug including a small use case. I've seen you
> post your typemaps a few times which is great, but would prefer up to
> date code if doing so again so as to not mislead future 'googlers'.

I reviewed the bug at

http://sourceforge.net/tracker/?func=detail&atid=101645&aid=1794247&group_id=1645

and I do not understand what the 'replace' attribute is good for; therefore I do not use it.

> > // Normal wrappers (for defined types) use this code
> > %typemap(csbody, noblock=1) SWIGTYPE
> > { //
> >   protected bool swigCMemOwn;
> >   protected internal $csclassname(IntPtr cPtr, bool cMemoryOwn) :
> base(cPtr) {
> >     if (!(swigCMemOwn = cMemoryOwn))
> > 		GC.SuppressFinalize(this);
> >   }
> This is a neat performance trick I've not seen before which I thought
> might be useful for the default typemaps. But after some pondering I
> think it is too risky to put into the default SWIG typemaps as it is
> possible that some users customisations will set swigCMemOwn to true
> after the constructor is called. I'd suggest making swigCMemOwn
> readonly to future proof your code with a compilation error... once
> you've done that I think you'll find that you could even get rid of the
> swigCMemOwn flag altogether.

Interesting idea, eliminating swigCMemOwn. One very minor problem: any shmuck can call
GC.ReRegisterForFinalize on the object. Anyway, it might be interesting to make swigCMemOwn readonly
and then wait to see if anyone posts a regression bug report.

> Could I ask you to add in a big DANGER sign in your comments here if
> you are going to post this onto the internet again as you are relying on
> behaviour that is not guaranteed in the C++ standard and is liable to
> subtle, hard to track bugs, particularly so as you have suppressed
> SWIGWARN_CSHARP_MULTIPLE_INHERITANCE.

Well, I only suppressed the warning because it's spurious. Anyway, here's my new comment:

// Note: In my wrappers there is no reason to call back into C++ to do an 
// upcast (and SWIG doesn't support multiple inheritance anyway), so I 
// removed that code from here. *** DANGER ***: this violates the letter 
// of the C++ standard, and may fail horribly (with a segfault or 
// something) if you use this particular typemap while wrapping classes 
// that use virtual inheritance or multiple inheritance.

> The idea of overriding Equals and GetHashCode and overloading operator==
> makes sense as it provides reference equals on the C++ instance level
> rather than on C# instances and I'm thinking of putting this as a
> default into SWIG. However, using a single base class implementation of
> this is incorrect and instead I'd generate the methods into every proxy
> class.

I don't think that's necessary. If the base-class value of swigCPtr compares equal in two different proxy
objects, surely the two proxies point to the same object?

> With regard to using the C++ operator==, the advice given in the MSDN
> links above says: "Consider overriding Equals on a reference type if the
> semantics of the type are based on the fact that the type represents
> some value(s)". Surely, if there is a C++ operator== the advice then
> applies and we should be using value equality. If say we are wrapping
> std::vector<T> where T is a class (not a pointer to a class), then using
> reference equals is just plain wrong as we are storing the object by
> value, not reference/pointer. If we are wrapping
> std::vector<T*> or std::vector<T&> then implementing reference equality
> makes sense and we could modify the specializations in std_vector.i to
> do this.

Ahh, hmm. I see your point. As it happens, I have been using SWIG to wrap vectors of VALUES like e.g.
vector<Point> (which comes out as a list of System.Drawing.Point on the C# side) and vector<int>.
Looking at the matter through that lens, I would like to have the IList<T> interface available in cases
like that.

I strongly agree that SWIG ought to detect equality of two C pointers by default. It's better to provide a
reasonable default (equality of C pointers) than the unreasonable default SWIG has now (reference
equality of proxy objects).

Equality of C pointers is good enough for many, if not most cases... but vector<T> where T is a SWIG-wrapped
type is not one of those cases :(

------------------------------------------------------------------------------
Andrea Fazzi | 3 Apr 2009 16:43
Picon
Gravatar

Nested structs and XML generated wrapper code

Hi all,

I noticed an unexpected behaviour in the generation of the XML wrapper
code of nested structs. It seems that the declaration of the nested
struct comes *after* the declaration of the container struct.

E.g.

typedef struct {
  struct {
    char a;
  } nested;
} my_struct;

Looking at SWIG documentation I understand that the example below should
be transformed in something like:

typedef struct {
  char a;
} my_struct_nested;

typedef struct {
  my_struct_nested nested;
} my_struct;

But it seems that the generated XML wrapper code doesn't reflect the
situation above. In fact, the definition of my_struct_nested comes
*after* the definition of my_struct. Is this the expected behaviour? 

I'm using SWIG version 1.3.40.

Thanks in advance.
Andrea

------------------------------------------------------------------------------
David Piepgrass | 3 Apr 2009 17:15
Favicon

Re: Python 2.6 and Visual Studio 2005

> Thanks for the help.
> I'm using python 2.6.1.
> I indeed had my environment variables wrong. I can now compile and link
> the "class" example, but I cannot link the "simple" example. Here is the
> output:
> 
> 1>------ Rebuild All started: Project: example, Configuration: Release
> Win32 ------
> 1>Deleting intermediate and output files for project 'example',
> configuration 'Release|Win32'
> 1>Performing Custom Build Step
> 1>In order to function correctly, please ensure the following
> environment variables are correctly set:
> 1>PYTHON_INCLUDE: c:\python26\include
> 1>PYTHON_LIB: c:\python26\libs\python26.lib
> 1>c:\Python26\swig\Examples\python\simple>..\..\..\swig.exe -python
> c:\Python26\swig\Examples\python\simple\example.i
> 1>c:\Python26\swig\Examples\python\simple>if errorlevel 1 goto
> VCReportError
> 1>c:\Python26\swig\Examples\python\simple>goto VCEnd
> 1>Compiling...
> 1>example_wrap.c
> 1>example.c
> 1>Generating Code...
> 1>Linking...
> 1>   Creating library .\Release/_example.lib and object
> .\Release/_example.exp
> 1>LIBCMT.lib(crt0.obj) : error LNK2019: unresolved external symbol _main
> referenced in function ___tmainCRTStartup
> 1>_example.pyd : fatal error LNK1120: 1 unresolved externals
> 1>Build log was saved at
> "file://c:\Python26\swig\Examples\python\simple\Release\BuildLog.htm"
> 1>example - 2 error(s), 0 warning(s)
> ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
> 
> Christophe

Since the linker is looking for main(), I'm guessing your project is set up to produce an .exe instead of a
.dll. Check your project settings.

------------------------------------------------------------------------------
Andrea Fazzi | 3 Apr 2009 16:33
Picon
Gravatar

Nested structs and XML wrapper code

Hi all,

I noticed an unexpected behaviour in the generation of the XML wrapper
code of nested structs. It seems that the declaration of the nested
struct comes *after* the declaration of the container struct.

E.g.

typedef struct {
  struct {
    char a;
  } nested;
} my_struct;

Looking at SWIG documentation I understand that the example below should
be transformed in something like:

typedef struct {
  char a;
} my_struct_nested;

typedef struct {
  my_struct_nested nested;
} my_struct;

But it seems that the generated XML wrapper code doesn't reflect the
situation below. In fact, the definition of my_struct_nested comes
*after* the definition of my_struct. Is this the expected behaviour? 

I'm using SWIG version 1.3.40. Full interface/wrapper code attached.

Thanks in advance.
Andrea

Attachment (nested_struct.tar.gz): application/x-compressed-tar, 4721 bytes
------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
Tamas Szekeres | 4 Apr 2009 00:10
Picon
Gravatar

SWIG 1.3.39 generates wrong C# wrapper

Hi All,

SWIG 1.3.39 creates uncompilable code with the for the C# interface, though the code generated with the previous versions have been compiling correcly.

As an example I have the following code:

%inline %{
void GDAL_GCP_Info_set( GDAL_GCP *h, const char * val ) {
  if ( h->pszInfo )
    CPLFree( h->pszInfo );
  h->pszInfo = CPLStrdup(val);
}
%}

which now generates the following code:

SWIGEXPORT void SWIGSTDCALL CSharp_GCP_Info_set(void * jarg1, char * jarg2) {
  GDAL_GCP *arg1 = (GDAL_GCP *) 0 ;
  char *arg2 = (char *) 0 ;
 
  arg1 = (GDAL_GCP *)jarg1;
  arg2 = (char *)jarg2;
  {
    {
      if (GDAL_GCP_Info_set(arg1,arg2)) delete [] GDAL_GCP_Info_set(arg1,arg2);
      if (arg2) {
        GDAL_GCP_Info_set(arg1,arg2) = (char *) (new char[strlen((const char *)arg2)+1]);
        strcpy((char *)GDAL_GCP_Info_set(arg1,arg2), (const char *)arg2);
      } else {
        GDAL_GCP_Info_set(arg1,arg2) = 0;
      }
    }
  }
}


Which is uncompilable, but with the previous versions I got something like:


SWIGEXPORT void SWIGSTDCALL CSharp_GCP_Info_set(void * jarg1, char * jarg2) {
  GDAL_GCP *arg1 = (GDAL_GCP *) 0 ;
  char *arg2 = (char *) 0 ;
 
  arg1 = (GDAL_GCP *)jarg1;
  arg2 = (char *)jarg2;
  {
    GDAL_GCP_Info_set(arg1,arg2);
 }
}


Could someone explain what have been changed between these versions causing this problem and how can I revert to the original behaviour?

Best regards,


Tamas



------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user

Gmane