Compiling GDAL and Implementing Java Binding on Ubuntu
1/19/24About 1 min
0. Prerequisites:
1. Install Some Basic Dependencies
sudo apt-get update
sudo apt-get install build-essential autoconf automake libtool pkg-config unzip ant swig libxml2-dev libgeos-dev libproj-dev libsqlite3-dev libtiff5-dev libjpeg-dev zlib1g-dev libpng-dev libgif-dev libjson-c-dev libcairo2-dev postgresql-server-dev-all sqlite3 libpq-dev2. Install Proj
wget https://download.osgeo.org/proj/proj-6.3.2.tar.gz
tar xzf proj-6.3.2.tar.gz
cd proj-6.3.2
./configure
sudo make
sudo make install3. Compile GDAL
# Fetch GDAL source code
wget https://download.osgeo.org/gdal/3.5.3/gdal-3.5.3.tar.gz
tar xzf gdal-3.5.3.tar.gz
cd gdal-3.5.3
# Configure GDAL compilation options
./configure --with-java=/home/vbox/java/openlogic-openjdk-17.0.9+9-linux-x64 --with-proj=/usr/local
# Compile and install
sudo make
sudo make install
# Test if installation is complete
gdalinfo --version4. Compile Java Binding
cd gdal-3.5.3/swig/java/Edit thejava.optconfiguration to set theJAVA_HOMEpath
JAVA_HOME = /home/vbox/java/openlogic-openjdk-17.0.9+9-linux-x64
JAVADOC=$(JAVA_HOME)/bin/javadoc
JAVAC=$(JAVA_HOME)/bin/javac
JAVA=$(JAVA_HOME)/bin/java
JAR=$(JAVA_HOME)/bin/jar
JAVA_INCLUDE=-I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux- Compile
make- Set the current location to the environment variable
export LD_LIBRARY_PATH=/home/vbox/gdal/gdal-3.5.3/swig/java/:$LD_LIBRARY_PATH
# Execute the `source /etc/profile` command to make the changes take effect immediately
source /etc/profile5. Some Common Issues
Error:
error while loading shared libraries: libgdal.so.31: cannot open shared object file: No such file or directoryReason: After
make install, the installation path is/usr/local/, which needs to be linked to/usr/
sudo ln -s /usr/local/lib/libgdal.so.31 /usr/lib/libgdal.so.31- Compilation error:
uint8_tundefined
Modify the code:
+ #include <cstdint>References
- Tongyi Qianwen
AI Translation | AI 翻译
This article was translated from Chinese to English by AI. If there are any inaccuracies, please refer to the original Chinese version.
本文由 AI 辅助从中文翻译为英文。如遇不准确之处,请以中文原版为准。
