[gdal-dev] CSharp bindings question

Tamas Szekeres szekerest at gmail.com
Wed Jun 10 12:33:20 PDT 2015


Hi Asa,

Thanks for the detailed investigation, I'll evaluate the result of the
changes and try to incorporate them in GDAL.

Best regards,

Tamas



2015-06-10 20:07 GMT+02:00 Asa Packer <apacker at biosonicsinc.com>:

> Hello again,
>
> Sorry, I posted this using the Nabble gateway, and the text I formatted as
> raw text did not come through correctly in email.  Here is another try.
>
> -Asa
> ---
> Hello,
>
> I am new to GDAL, and SWIG.  I spent yesterday getting GDAL 1.11.2 compiled
> and ran into similar errors trying to build the C# bindings as are being
> discussed on this thread.  I am on Windows (7 Pro SP1 x64) using Visual
> Studio 2013's command prompt.  I am using the current version of swigwin,
> 3.0.5.
>
> FWIW, I was able to fix the errors by making the following changes.  Since
> I
> don't really understand what SWIG is doing very well, I'm not sure how safe
> these are, although they seem fairly minor.  I apologize if this has
> already
> been discussed somewhere else - I'm reporting them just in case they are
> helpful.
>
> 1. Change line 95 of
> gdal-1.11.2/swig/include/csharp/swig_csharp_extensions.i from
>   public $csclassname(IntPtr cPtr, bool cMemoryOwn, object parent) :
> base($modulePINVOKE.$csclassnameUpcast(cPtr), cMemoryOwn, parent) {
> to
>   public $csclassname(IntPtr cPtr, bool cMemoryOwn, object parent) :
> base($modulePINVOKE.$csclassname_SWIGUpcast(cPtr), cMemoryOwn, parent) {
>
> This fixes errors saying that the upcast function does not exist.  These
> errors happen starting with SWIG 2.0.0.
>
> 2. Delete lines 12-17 of
> gdal-1.11.2/swig/include/csharp/swig_csharp_extensions.i - this fixes the
> duplicate static constructor error CS0111.  This error is related to the
> following entry from the SWIG changelog
> http://www.swig.org/Release/CHANGES.
> The change was first released in SWIG 2.0.0.
>
> 2010-05-23: wsfulton
>             [C#] Fix #2957375 - SWIGStringHelper and SWIGExceptionHelper
> not
> always being
>             initialized before use in .NET 4 as the classes were not marked
> beforefieldinit.
>             A static constructor has been added to the intermediary class
> like this:
>
>               %pragma(csharp) imclasscode=%{
>                 static $imclassname() {
>                 }
>               %}
>
>             If you had added your own custom static constructor to the
> intermediary class in
>             the same way as above, you will have to modify your approach to
> use static variable
>             initialization or define
> SWIG_CSHARP_NO_IMCLASS_STATIC_CONSTRUCTOR - See csharphead.swg.
>
>             *** POTENTIAL INCOMPATIBILITY ***
>
> 3. Add the "-DSWIG2_CSHARP" flag to my SWIG variable in
> gdal-1.11.2/nmake.local.  This fixes numerous errors about basic .NET types
> like IntPtr not being defined.  This is related to the following entry from
> the SWIG changelog, first released in version 3.0.0:
>
> 2013-11-09: wsfulton
>             [C#] Apply patch #79 from Brant Kyser
>               - Remove using directives from the generated C# code and
> fully
> qualify the use of all .NET
>                 framework types in order to minimize potential name
> collisions from input files defining
>                 types, namespace, etc with the same name as .NET framework
> members.
>               - Globally qualify the use of .NET framework types in the
> System namespace
>               - Remove .NET 1.1 support, .NET 2 is the minimum for the C#
> module
>
>             This is a potential backwards compatibility break if code has
> been added relying on these using
>             statements that used to be generated:
>
>               using System;
>               using System.Runtime.InteropServices;
>
>             The quick fix to add these back in is to add the -DSWIG2_CSHARP
> command line option when
>             executing SWIG. See CSharp.html documentation for more info.
>
>             *** POTENTIAL INCOMPATIBILITY  ***
>
> Thanks!  I appreciate all the work that you and others have done to make
> GDAL so nice.
>
> Asa
>
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20150610/d1e9b0da/attachment.html>


More information about the gdal-dev mailing list