Building gdal-java on Mac OS X

Building gdal on Mac OS X

The following procedure has been adapted form the GDAL CI (opens in a new tab).

set -e
xcode-select --installs
brew install cmake
brew install proj
brew install boost
brew install swig
brew install sqlite
brew install thrift
brew install --cask miniconda
git clone
git checkout v3.6.4
conda update -n base -c defaults conda
conda install -y compilers automake pkgconfig cmake
conda config --set channel_priority strict
conda install --yes --quiet proj=7.1.1=h45baca5_3 python=3.8 swig -y
conda install --yes --quiet libgdal=3.1.4=hd7bf8dc_0  --only-deps -y
find ${CONDA_PREFIX}/lib -name '*.la' -delete
mkdir build
cd build
CFLAGS="-Wextra -Werror -Wunused-variable" CXXFLAGS="-Wextra -Werror -Wunused-variable" cmake .. \
        -DCMAKE_INSTALL_PREFIX=$HOME/install-gdal \
make -j3
make install

After this, the library can be found in ~/install-gdal/share/java/libgdalalljni.dylib.

When starting a java application, the library can be loaded with the following command:

java -Djava.library.path=~/install-gdal/share/java -jar myapp.jar (opens in a new tab) (opens in a new tab) (opens in a new tab)