| 1 | |
| 2 | = GDAL/OGR CSharp interface compilation = |
| 3 | |
| 4 | 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. |
| 5 | |
| 6 | == Building on Windows == |
| 7 | |
| 8 | For building the C# interface the GDAL core should be compiled first according to the [http://trac.osgeo.org/gdal/wiki/BuildingOnWindows Windows build instructions]. |
| 9 | |
| 10 | === Setting up a proper environment === |
| 11 | |
| 12 | 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. |
| 13 | |
| 14 | === Creating the SWIG interface code === |
| 15 | |
| 16 | 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. |
| 17 | |
| 18 | For creating the interface execute the following command. |
| 19 | |
| 20 | {{{ |
| 21 | C:\GDAL\swig\csharp> nmake /f makefile.vc interface |
| 22 | }}} |
| 23 | |
| 24 | === Compiling the code === |
| 25 | |
| 26 | After creating the interface the code can be compiled as: |
| 27 | |
| 28 | {{{ |
| 29 | C:\GDAL\swig\csharp> nmake /f makefile.vc |
| 30 | }}} |
| 31 | |
| 32 | Upon a successful compilation the following files are created: |
| 33 | |
| 34 | {{{ |
| 35 | gdal_csharp.dll |
| 36 | ogr_csharp.dll |
| 37 | osr_csharp.dll |
| 38 | gdalconst_csharp.dll |
| 39 | gdal_wrap.dll |
| 40 | ogr_wrap.dll |
| 41 | osr_wrap.dll |
| 42 | gdalconst_wrap.dll |
| 43 | various sample applications (*.exe) |
| 44 | }}} |
| 45 | |
| 46 | *_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. |
| 47 | |
| 48 | === Testing the successful compilation === |
| 49 | |
| 50 | For testing the successful compilation you can use: |
| 51 | |
| 52 | {{{ |
| 53 | C:\GDAL\swig\csharp> nmake /f makefile.vc test |
| 54 | }}} |
| 55 | |
| 56 | 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. |
| 57 | |
| 58 | == Specifying the MSVC version == |
| 59 | |
| 60 | When compiling with the Visual Studio 2005 you might have to specify the compiler version by editing nmake.opt as: |
| 61 | |
| 62 | {{{ |
| 63 | MSVC_VER=1400 |
| 64 | }}} |
| 65 | |
| 66 | Alternatively you can pass this option to the nmake command line as |
| 67 | |
| 68 | {{{ |
| 69 | C:\GDAL\swig\csharp> nmake /f makefile.vc MSVC_VER=1400 |
| 70 | }}} |
| 71 | |
| 72 | == Using static vs. dynamic linking with the gdal libraries == |
| 73 | |
| 74 | The default approach embeds the gdal/ogr code into the corresponding *_wrap.dll to minimize the dependency of the created files. In some cases you might want to link against the core gdal*.dll instead. To enable this option comment out the |
| 75 | |
| 76 | {{{ |
| 77 | CSHARP_STATIC_LINKAGE = YES |
| 78 | }}} |
| 79 | |
| 80 | entry in the csharp.opt file. |
| 81 | |
| 82 | == Using MONO on Windows == |
| 83 | |
| 84 | 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: |
| 85 | |
| 86 | {{{ |
| 87 | #MONO = YES |
| 88 | }}} |
| 89 | |
| 90 | And make mcs.exe available in the PATH. |
| 91 | |
| 92 | == Compiling on a WIN64 platform == |
| 93 | |
| 94 | 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. |
| 95 | |
| 96 | 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. |
| 97 | |
| 98 | Alternatively you can pass this option to the nmake command line as |
| 99 | |
| 100 | {{{ |
| 101 | C:\GDAL\swig\csharp> nmake /f makefile.vc WIN64=YES |
| 102 | }}} |
| 103 | |
| 104 | This setting will allow to specify the proper platform (/platform:anycpu) for the csharp compiler. |
| 105 | |
| 106 | IMPORTANT NOTICE: |
| 107 | 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. |
| 108 | |
| 109 | == Building on Linux/OSX == |
| 110 | |
| 111 | TODO |