Gdal compiling the C # development version

Source: Internet
Author: User

Gdal compilation is troublesome, there are many kinds of things, today I compile the gdal encountered problems and the previous a bit different, for reference only.

1. Download Gdal Source code

Gdal Source: Https://trac.osgeo.org/gdal/wiki/DownloadSource

I downloaded the latest gdal211, I do not know why, the later compiled is the version of gdal201.

2. Start compiling the development version of C + +

Gdal method provided in window compilation: Http://trac.osgeo.org/gdal/wiki/BuildingOnWindows

To compile the 64-bit gdal, I modified the code at line 189 of the nmake.opt file to change the #WIN64 =yes to win64=yes

Then use CMD to set the compilation environment:

" C:\Program Files (x86) \microsoft Visual Studio 10.0\vc\vcvarsall.bat " AMD64

Then go to the Gdal directory and execute the following command in turn:

1, c:\gdal> nmake/f MAKEFILE.VC2, C:\GDAL> NMAKE/F makefile.vc install3, C:\GDAL> nmake/f MAKEFILE.VC Devinstall

After compiling, the Warmerda folder is generated below the C drive, and the files are used to provide C + + compilation, such as:

Note: If the compilation environment is set incorrectly, the following error will be prompted when the first step is compiled:

3. Compiling the version used by C #

Compiling the version used by C # requires the Swig tool, as follows: Http://prdownloads.sourceforge.net/swig/swigwin-3.0.10.zip

After downloading, unpack, open nmake.opt, change swig=swig.exe to Swig =e:\swigwin-3.0.10\swig.exe

Then go to the Swig\csharp directory and execute the following command after the above three sentences are compiled:

1. NMAKE/F makefile.vc Install

Note: The following issue occurs during the 1 compilation:

Learn from Blog: gdal compile C#,python support errors

Issue 1, interface redefinition

Osr\osrpinvoke.cs (192): Error CS0111: Type "OSGeo.OSR.OsrPINVOKE" has defined a named "Osrpinvoke" Members with the same parameter type
Osr\osrpinvoke.cs (188): (the symbol position associated with the previous error) Nmake:fatal error U1077: "C:\Windows\Microsoft.NET\ Framework\v4. 0.30319\CSC. EXE ": Return code"0x1"

Workaround: Enter into the. \GDAL-1.9.2\SWIG\CSHARP\GDAL|OGR|OSR three folders, find GdalPINVOKE.cs, OgrPINVOKE.cs, OsrPINVOKE.cs, remove the duplicate parameter types from the prompt, such as the following error:

Issue 2: interface member name called Error, error message:

Gdal\band.cs (+
Gdal\dataset.cs (+)
Gdal\driver.cs (,Bayi
Nmake:fatal error U1077: "C:\Windows\Microsoft.NET\Framework\v4. 0.30319\CSC. EXE ": Return code"0x1"

The GdalPINVOKE.cs defines the interface as follows:

The band class (for example) is called as follows:

Modify the interfaces in the three classes to:

 PublicDriver (IntPtr cPtr,BOOLCmemoryown,ObjectParent):Base(Gdalpinvoke.driver_swigupcast (CPTR), Cmemoryown, parent) {swigcptr =NewHandleRef ( This, CPTR);

PublicDataset (IntPtr cPtr,BOOLCmemoryown,ObjectParent):Base(Gdalpinvoke.dataset_swigupcast (CPTR), Cmemoryown, parent) {swigcptr =NewHandleRef ( This, CPTR);

PublicBand (IntPtr cPtr,BOOLCmemoryown,ObjectParent):Base(Gdalpinvoke.band_swigupcast (CPTR), Cmemoryown, parent) {swigcptr =NewHandleRef ( This, CPTR);

After the modification can be compiled successfully, after the successful compilation, the C:\warmerda\bld folder will generate a Scharp file for C # programming use.

4. Test procedure Error

1. Error occurred while testing program registered Gdal


Additional Information: Security transparency Method "OSGeo.GDAL.Gdal.AllRegister ()" Attempts to invoke native code through method "OSGeo.GDAL.GdalPINVOKE.AllRegister ()" failed. Methods must be security-critical or security-critical to invoke native code.

Workaround:

Modify the C # wrapper class code generated by Swig, which is forced to be declared as callable by security-transparent code. \swig\csharp\gdal\gdal.cs class and. The \swig\csharp\gdal\dataset.cs class, for example, adds the following two lines of code at the beginning of its class declaration:

using System.Security; [SecuritySafeCritical]

As follows:

If the problem still occurs, add [securitysafecritical].

2. An error occurred after the test program was successful:

Workaround, add [securitysafecritical] to the geometry Dispose method, as shown in

Similar problem resolution methods are the same.

Gdal compiling the C # development version

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.