Compile and install GDAL on Linux (centos8) system

created at 08-23-2021 views: 95

This article introduce the install of GDAL in Linux (centos 8) and the solution for jpeg2000dataset.cpp:35:10: fatal error: jasper/jasper.h during installation.

Introduction

The GDAL library is a very powerful library for processing geographic information, and I want to use it to do CAD to geojson work. The test was carried out on windows, and now it needs to be deployed to linux. If you encounter a hurdle in the installation, record it.

OS version

[root@cumt gdal-2.2.1]# cat /proc/version 
Linux version 4.18.0-193.el8.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 8.3.1 20191121 (Red Hat 8.3.1-5) (GCC)) #1 SMP Fri May 8 10:59:10 UTC 2020

GDAL install

step1 download

download link

we can directly download like this:

# cd /storage/software/gdal
# wget -c http://download.osgeo.org/gdal/2.2.1/gdal-2.2.1.tar.gz 

step2 Decompress the source code and enter the decompression package:

# tar xvf gdal-2.2.1.tar.gz
# cd gdal-2.2.1

step3 Install the libraries needed for compilation:

# yum install -y gcc make subversion gcc-c++ sqlite-devel libxml2-devel swig expat-devel libcurl-devel python36-devel

python36-devel If you can’t find it, use: python-devel

step4 Perform configuration, compilation, and installation:

# ./configure
# make
# make install

In the compilation step, I got an error:

jpeg2000dataset.cpp:35:10: fatal error: jasper/jasper.h: No such file or directory
 #include <jasper/jasper.h>
          ^~~~~~~~~~~~~~~~~
compilation terminated.

Debug

Look carefully at the error: Cannot find jasper..., it is an error reported by calling the file jpeg2000dataset.cpp
What is jasper? I didn’t study it, but finally found the corresponding explanation on GDAL official website:

Implemented as gdal/frmts/jpeg2000/jpeg2000dataset.cpp.

You need modified JasPer library to build this driver with GeoJP2 support enabled. Modified version can be downloaded from http://download.osgeo.org/gdal/jasper-1.900.1.uuid.tar.gz

Download jasper directly to install:
Download jasper: http://download.osgeo.org/gdal/jasper-1.900.1.uuid.tar.gz
Installation: refer to the official doc

All steps are executed in order:

# cd /storage/software/JasPer
# wget http://download.osgeo.org/gdal/jasper-1.900.1.uuid.tar.gz
# tar xvf jasper-1.900.1.uuid.tar.gz
# cd jasper-1.900.1.uuid
# ./configure
# make
# make install

After jasper is installed, re-execute step 4 (4. Perform configuration, compile, and install:)

# vi ~/.bashrc

Add the following at the end:

export PATH=$PATH:/usr/local/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

save

# :wq

use:

# source ~/.bashrc

If this step is not executed, an error will be reported: error: gdalinfo: error while loading shared libraries: libgdal.so.20: cannot open shared object file: No such file or directory
Cannot find the shared library, which means that the addition in bashrc does not take effect.

6.Check if the gdal is installed successfully:

# gdalinfo --version
created at:08-23-2021
edited at: 08-23-2021: