wiki:GdalOgrCsharpCompile

GDAL/OGR CSharp interface compilation

This chapter describes the primary steps when creating the GDAL/OGR C# binaries from the source. In most cases using the precompiled binaries from the FWTools package would be sufficient instead of manually compiling the interface files.

Building on Windows

For building the C# interface the GDAL core should be compiled first according to the Windows build instructions.

Setting up a proper environment

Before compiling the code you should prepare a number of environment variables for the compiler you use. If you don't want to bother with executing the proper vcvars*.bat you might use the development environment specific command prompt to accomplish this task. When using a Win64 compilation be careful to activate the x64 version of the command prompt installed on your system.

Creating the SWIG interface code

For creating the interface the swigwin-1.3.31 package should be downloaded and extracted. You should edit nmake.opt adding the actual location of the swig.exe file.

For creating the interface execute the following command.

nmake /f makefile.vc interface 

Previous Step make's error when regenerates the *PINVOKE.cs files ,so skip to next step ,it will work

Compiling the code

After creating the interface the code can be compiled as:

C:\GDAL\swig\csharp> nmake /f makefile.vc

Upon a successful compilation the following files are created:

gdal_csharp.dll
ogr_csharp.dll
osr_csharp.dll
gdalconst_csharp.dll
gdal_wrap.dll
ogr_wrap.dll
osr_wrap.dll
gdalconst_wrap.dll
various sample applications (*.exe)

*_csharp.dll is the managed part of the interface. You should add a reference to these assemblies for using the classes of the interface. These *_csharp.dll-s will load the corresponding *_wrap.dll which are the unmanaged part of the interface hosting the code of the gdal core.

Testing the successful compilation

For testing the successful compilation you can use:

C:\GDAL\swig\csharp> nmake /f makefile.vc test

This command will invoke some of the sample applications. For the proper execution the location of the proj.dll should be available in the PATH.

Specifying the MSVC version

When compiling with the Visual Studio 2005 you might have to specify the compiler version by editing nmake.opt as:

MSVC_VER=1400

Alternatively you can pass this option to the nmake command line as

C:\GDAL\swig\csharp> nmake /f makefile.vc MSVC_VER=1400

Using MONO on Windows

If you have the Windows version of the MONO package installed you can compile the C# code using the MONO compiler. In this case uncomment the following entry in csharp.opt:

#MONO = YES 

And make mcs.exe available in the PATH.

Compiling on a WIN64 platform

You can compile GDAL on a Win64 platform creating either Win32 or Win64 binaries. You should take care of setting up the proper environment variables for the corresponding compiler by using the proper vcvars.bat or using the Visual Studio 2005 x64 command prompt.

For creating Win64 binaries you should compile the gdal core and the C# interface using the 64 bit compiler version, and specify WIN64=YES in nmake.opt.

Alternatively you can pass this option to the nmake command line as

C:\GDAL\swig\csharp> nmake /f makefile.vc WIN64=YES

This setting will allow to specify the proper platform (/platform:anycpu) for the csharp compiler.

IMPORTANT NOTICE: The 64 bit version of the gdal will require to have 64 bit versions of the dependent libraries. For example you might have to compile a 64 bit version of the proj.dll so as to run the csharp make test successfully.

Building on Linux/OSX

TODO

Last modified 9 years ago Last modified on Jan 16, 2011, 3:37:07 AM