Gdal comprehensive sorting-5: gdal compilation instructions

Source: Internet
Author: User
Document directory
  • 1. Simple Compilation
  • Ii. Custom Compilation

On the Internet, I can see that this article is fully written, and it is in Chinese. I just turned around and learned it.
Some of the content is repeated, but it does not affect. Very good information.

Mainly from http://blog.csdn.net/liminlu0314? Viewmode = Contents

Gdal compilation description 1. Simple Compilation

1. Compile with Visual Studio ide

First, go to the source code directory of gdal, and you can see several SLN suffix file names, such as makedal10.sln, makedal80.sln, makedal71.sln, and makedal90.sln. These files are the project files of Visual Studio. The following numbers correspond to the vs version number. For example, 71 represents vs2003, 80 represents vs2005, 90 represents vs2008, and 10 represents vs2010. Open the corresponding file based on the vs version installed on your computer, as shown in (use vs2008sp1 to open the makegdal90.sln file ):

Right-click the solution on the left and select "generate" or "regenerate" in the pop-up menu. Then, gdal starts compilation and waits for the prompt in the output window to complete the execution, after the information is generated successfully, it indicates that the gdal has been compiled. At the same time, gdal will appear in the source code directory of gdal. lib, gdal_ I .lib, gdal18.dll, and other files. if the OPT file is used, a folder named "C: \ warmerda \ BLD" will appear in your drive C, which contains three folders, bin, respectively, data and HTML. The bin folder stores the compiled gdal executable programs, including more than a dozen tool sets provided by gdal. The data folder is the data folder introduced in section 1; the HTML folder contains instructions on various data formats.

2. Compile with cmd command line

Use the CMD command line to compile the program. First, go to the "Start Menu \ All Programs \ Microsoft Visual Studio 2008 \ Visual Studio Tools \ Visual Studio 2008 command prompt ", click "Visual Studio 2008 command prompt" to bring up the CMD interface:

Run the CD command to switch to the gdal source code directory, as shown in:

Switch to the source code directory of gdal, input the following command lines in sequence, and press Enter. Wait until the compilation is complete.

Nmake-F makefile. VC

Nmake-F makefile. VC install

Nmake-F makefile. VC devinstall

There are other commands, such:

Nmake-F makefile. VC clean

Nmake-F makefile. VC msvc_ver = 1400 clean

Nmake-F makefile. VC msvc_ver = 1400 DEBUG = 1

The meanings of the above six lines of commands are as follows:

Compile the gdal Library

Compile the gdal library and install it (here, the installation means to copy the generated DLL, EXE and other files to the C: \ warmerda \ BLD directory ),

Compile the gdal library and install the developer mode (the installation means the same as above. The developer Mode means to copy the header files in the include folder used for development together with the Lib file to the C: \ warmerda \ BLD directory, in this case, two folders, including include and Lib, are displayed in the C: \ warmerda \ BLD directory, respectively. The gdal header file and Lib file are respectively stored for calling the gdal library ).

Clearing the gdal Library also deletes the temporary files generated by compiling the gdal library, which is equivalent to clearing commands in the vs environment.

The function is the same as above, but a msvc_ver = 1400 is added, indicating that vs2005 is used for compilation.

Compile the debug mode of the gdal library, which can be used to debug the gdal source code.

Ii. Custom Compilation

Gdal is not only powerful in reading raster and vector data, but also in the following aspects. First, it can perform common operations between vector images, such: request, request, and buffer. Second, you can perform projection and coordinate transformation. If you use the default gdal compilation method, you will not be able to use the two very powerful functions described above, because the two gdal functions are based on the other two open source libraries geos (geometry engine, open source) Library and proj4 library. Next we will give a simple description of these two libraries and how to modify the compilation file so that gdal can have these two functions.

1. Integrate geos

On the geos library description, there are a lot of online, at the same time in the geos official website http://geos.osgeo.org has a detailed description, simply put, geos provides the C ++ language for simple geometric element object operations in OGC specifications. In the Geographic Information System field, the topological model is important, and its calculation method is simple but difficult to implement. This makes geos different from other projects, namely, space predicates and space operations ". A space predicate compares two spatial objects and returns a Boolean value as a result. It indicates that there is a special relationship between two spatial objects. For example, typical spatial predicates include contains (), intersects (), touches (),
Andcrosses () function. The implementation of these functions in the geos project is exceptionally strong. Even singular geometric objects or temporary coordinate system operations cannot make the operations abnormal or wrong. At present, the vast majority of commercial software is still relatively mature in the most basic space predicate processing, which is the significance of the geos project. Space Operations are mainly used to calculate two geometric objects and return a new ry. Typical operation functions such as difference (), Union (), and buffer. Operation algorithms in geos have been extensively tested. The geos class library is widely used in various open-source space information software projects. With geos, it can be implemented based on the latest standardized geometric entities, and also has the implementation of complex spatial methods.

 

For the description and compilation of geos, a separate file will be provided later. Here we assume that the compiled geos library has been downloaded.

 

Use notepad or another text editor to open nmake in the gdal source code directory. in the OPT file, find the phrase "# uncomment for geos support", which is about 405 lines. Run the following three lines of code:

# Geos_dir = C:/warmerda/geos

# Geos_cflags =-I $ (geos_dir)/capi-I $ (geos_dir)/source/headers-dhave_geos

# Geos_lib = $ (geos_dir)/source/geos_c_ I .lib

To:

Geos_dir = F: \ work \ 3rdpart \ geos-3.2.2

Geos_cflags =-I $ (geos_dir)/capi-I $ (geos_dir)/source/headers-dhave_geos

Geos_lib = $ (geos_dir)/source/geos_c_ I .lib

Among them, F: \ work \ 3rdpart \ geos-3.2.2 is the main directory of my local geos storage, the next two lines set the geos header file directory and Lib file path. Save the settings. The comparison result is as follows:

After saving nmake. Opt, follow the compilation method in step 1 to compile it. The compiled gdal will support operations between images. The function is mainly used in the OGR library and will be described in detail later in the OGR library. After compilation, do not forget to copy the geos_c.dll file to the same directory of gdal18.dll. Otherwise, you will be prompted to not find the geos_c.dll file.

2. Integrate proj4

Proj4 is an open-source coordinate projection conversion class library, which can be used to complete the conversion between two sets of different cartography projection systems. It can also be successfully converted between different elliptical bodies or. The algorithms used in gdal, such as coordinate transformation, projection conversion, geometric correction, and normal injection correction, cannot be separated from coordinate transformation. That is to say, to use these algorithms, the support of the proj4 library is required. In the same geos library configuration method, locate the proj4 library in the nmake. Opt file, which is about 352 rows. Run the following three lines of code:

# Proj_flags =-dproj_static

# Proj_include =-ID: \ projects \ proj.4 \ SRC

# Proj_library = D: \ projects \ proj.4 \ SRC \ proj_ I .lib

To:

# Proj_flags =-dproj_static

Proj_include =-If: \ work \ 3rdpart \ proj-4.7.0 \ SRC

Proj_library = F: \ work \ 3rdpart \ proj-4.7.0 \ SRC \ proj_ I .lib

The first line indicates whether static links are used. The second line indicates the path where proj inventory is placed, and the third behavior is the path where the Lib file of proj library is located. Save the modification as follows:

Just like the geos library, after saving nmake. Opt, compile it according to the compilation method in step 1. The use of the proj library will be described in a simple article later. After compilation, do not forget to copy the proj. dll file to the same directory of gdal18.dll. Otherwise, you will be prompted to not find the proj. dll file.

3. Integrate HDF Data Reading

Based on the introduction of the above geos and proj libraries, I believe that the gdal configuration file, nmake. OPT has a preliminary understanding, so the following is the same for reading HDF data using gdal. Download The hdf4 and hdf5 libraries first, I used hdf4.2.6 and HDF5-1.8.7 two libraries, In the HDF official network has compiled the library, directly download the compiled library can be, for HDF library compilation, I have not compiled, it should be similar to other open-source libraries. At the same time, the official website provides a 32-bit library and a 64-bit library. Here we will introduce the 32-bit library, followed by a compilation introduction of the 64-bit gdal library.

Decompress the downloaded hdf4.2.6 and HDF5-1.8.7 libraries and modify about 278 lines in the nmake. Opt file. The Code is as follows:

# Uncomment thefollowing and update toenable ncsa hdf Release 4 support.

# Hdf4_plugin = No

# Hdf4_dir = D: \ warmerda \ hdf41r5

# Hdf4_lib =/libpath: $ (hdf4_dir) \ Lib ws2_32.lib

# Uncomment thefollowing and update toenable ncsa hdf Release 5 support.

# Hdf5_plugin = No

# Hdf5_dir = c: \ warmerda \ supportlibs \ hdf5 \ 5-164-win

# Hdf5_lib = $ (hdf5_dir) \ dll \ hdf5dll. Lib

Modify it to the following code:

# Uncomment thefollowing and update toenable ncsa hdf Release 4 support.

Hdf4_plugin = No

Hdf4_dir = F: \ work \ 3rdpart \ hdf4.2.6 _ win_x86

Hdf4_lib = $ (hdf4_dir) \ dll \ hd1_m. Lib $ (hdf4_dir) \ dll \ hm1_m. Lib \

$ (Hdf4_dir) \ Lib \ hd0000.lib $ (hdf4_dir) \ Lib \ hm0000.libws2 _ 32.lib

# Uncomment thefollowing and update toenable ncsa hdf Release 5 support.

Hdf5_plugin = No

Hdf5_dir = F: \ work \ 3rdpart \ HDF5-1.8.7_win_x86

Hdf5_lib = $ (hdf5_dir) \ dll \ hdf5dll. Lib

The comparison code is as follows:

Save, compile gdal, and copy the DLL files in the DLL folder of the HDF Library to the same directory of gdal18.dll.

Iii. Other aspects 1. Use makegdal_gen.bat

The role of makegdal_gen.bat has been described in the previous article, and the following describes how to use this file to generate vs project files.

First, open the CMD command line window, use the CD command to switch to the gdal source code directory, and enter makegdal_gen.bat to press Enter. A simple and practical tool is provided, as shown in:

This tool is used as a batch processing tool with command line parameters, and write a program with a command line ). The basic syntax of the tool is as follows:

Makegdal_gen 7.10> makegdal71.vcproj

Makegdal_gen 8.00> makegdal80.vcproj

The preceding example shows that the command line parameters of the tool are respectively the vs version number. For the specific version number, refer to the first section of this article, and then follow the "> ", finally, the name of the output vs project. Now I want to use this command line to generate a vs2008 project file. I can enter the following command and press Enter:

 

Makegdal_gen 9.00> makegdal90.vcproj

2. Compile gdal in a 64-bit System

The compilation of gdal 64-bit systems is basically the same as that of 32-bit systems. First, open the Configuration Manager in the vs project, then, select create from the drop-down list of the Active solution platform. Then, the create solution platform dialog box is displayed, select the new platform as x64 (64-bit compiling environment needs to be installed when vs is installed), and then click OK. Finally, select x64 in vs for compilation. As shown in:

 

For cmd command line compilation, it is basically different from the beginning of this article, except that the "visual studio2008 command prompt" is not selected in the Start menu, but the "visual studio2008 x64 compatible tool command prompt" is selected ", the remaining compilation steps are the same as above.

Before compilation starts, you also need to open the nmake. Opt file, find "# win64 = yes" in the 131 line, remove "#" from the previous line, save it, and start compilation. If this is the case, congratulations. If you cannot compile it smoothly, you need to perform a little setup according to the following steps.

1: In the nmake. Opt file under the gdal directory, find the sym_prefix definition, which should be around 438 lines

Changing sym_prefix = _ to sym_prefix = is to remove the last underline.

2: In the makefile. VC file under the gdal directory, find about 46 lines of code, as shown below:

Base_include =/include: _ gdalsimpleimagewarp @ 36 \

/Include: _ gdalreprojectimage @ 48 \

/Include: _ gdalcomputemediancutpct @ 32 \

/Include: _ gdalditherrgb2pct @ 28 \

/Include: _ octnewcoordinatetransformation @ 8 $ (vb6_safearraysym)

 

To:

Base_include =/include: $ (sym_prefix) gdalsimpleimagewarp \

/Include: $ (sym_prefix) gdalreprojectimage \

/Include: $ (sym_prefix) gdalcomputemediancutpct \

/Include: $ (sym_prefix) gdalditherrgb2pct \

/Include: $ (sym_prefix) octnewcoordinatetransformation $ (vb6_safearraysym)

It is to delete the number after. Compile now. Wish you success! For more information, see my blog: http://liminlu0314.blog.163.com/blog/static/111800520106223508717/.

3. An error occurred while opening the Chinese path after gdal1.8.

For more information, see http://blog.csdn.net/liminlu0314/article/details/6610069.

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.