Opened 8 years ago

Closed 7 years ago

Last modified 7 years ago

#6622 closed defect (invalid)

Compiling C# bindings on Linux

Reported by: jealie Owned by: warmerdam
Priority: normal Milestone:
Component: default Version: unspecified
Severity: normal Keywords:
Cc: tamas

Description

Compiling the C# SWIG bindings for GDAL on Linux requires modifying manually the source code.

I got the errors below with GDAL version 2.1.1 and SWIG versions 1.3 and 2.0. Other GDAL/SWIG versions could be affected. Most probably all Linux systems are affected (I got the same errors on two 32 and 64 bits virtual machines running Ubuntu 16.04).

In this ticket I report the error messages, as well as a manual workaround to solve them. Hopefully someone will be able to use this info to prepare a patch.

First error

Running make in the swig/csharp directory fails:

$ make
[...]
osr/OsrPINVOKE.cs(192,10): error CS0111: A member `OSGeo.OSR.OsrPINVOKE.OsrPINVOKE()' is already defined. Rename this member or use different parameter types
osr/OsrPINVOKE.cs(188,10): (Location of the symbol related to previous error)
Compilation failed: 1 error(s), 1 warnings
GNUmakefile:65: recipe for target 'gdal_csharp' failed
make: *** [gdal_csharp] Error 1

=> The solution was to edit the files osr/OsrPINVOKE.cs ; ogr/OgrPINVOKE.cs ; ogr/OsrPINVOKE.cs ; gdal/GdalPINVOKE.cs and remove the double declaration around line 190.

Second error

After fixing the first error, make is able to go further but fails with:

$ make
[...]
gdal/Band.cs(17,79): error CS0117: `OSGeo.GDAL.GdalPINVOKE' does not contain a definition for `BandUpcast'
gdal/GdalPINVOKE.cs(14,7): (Location of the symbol related to previous error)
gdal/Dataset.cs(17,82): error CS0117: `OSGeo.GDAL.GdalPINVOKE' does not contain a definition for `DatasetUpcast'
gdal/GdalPINVOKE.cs(14,7): (Location of the symbol related to previous error)
gdal/Driver.cs(17,81): error CS0117: `OSGeo.GDAL.GdalPINVOKE' does not contain a definition for `DriverUpcast'
gdal/GdalPINVOKE.cs(14,7): (Location of the symbol related to previous error)
Compilation failed: 3 error(s), 1 warnings
GNUmakefile:65: recipe for target 'gdal_csharp' failed
make: *** [gdal_csharp] Error 1

=> The solution was:

  • edit the files gdal/Band.cs and change the variable names at line 17 from BandUpcast to Band_SWIGUpcast
  • edit gdal/Dataset.cs and change DatasetUpcast into Dataset_SWIGUpcast
  • edit gdal/Driver.cs and change DriverUpcast into Driver_SWIGUpcast

In case it is relevant, I wrote more developed, step-by-step compilations notes on this github: https://github.com/jealie/binaries_GDAL_Csharp/blob/master/compilationNotes.txt .

Change History (4)

comment:1 by Even Rouault, 8 years ago

Cc: tamas added

Are you sure you are really using SWIG 1.3.40 ? I get those errors with SWIG >= 2.0, but with SWIG 1.3.40 this builds fine.

comment:2 by jealie, 8 years ago

Yes, swig -version returns:

SWIG Version 1.3.40

Compiled with g++ [x86_64-unknown-linux-gnu]

To be sure I just ran again the whole build process and I can confirm that I hit the exact same bumps with SWIG 1.3.40.

comment:3 by Even Rouault, 7 years ago

Resolution: invalid
Status: newclosed

I strongly suspect you didn't run "make clean" in swig/csharp, and thus the SWIG generated file weren't refreshed when trying with 1.3.40 (that's how I can reproduce your issue). That's how I can reproduce your issue. Closing under that assumption

comment:4 by Even Rouault, 7 years ago

Closing since https://trac.osgeo.org/gdal/ticket/6465 is still opened and discuss compatibility with SWIG 3.0.8

Note: See TracTickets for help on using tickets.