Skip to content

Instantly share code, notes, and snippets.

@zty5678
Last active May 13, 2025 03:19
Show Gist options
  • Select an option

  • Save zty5678/7cb8372e5cbfae1f3c152d62986f0f02 to your computer and use it in GitHub Desktop.

Select an option

Save zty5678/7cb8372e5cbfae1f3c152d62986f0f02 to your computer and use it in GitHub Desktop.
Mac 编译 java 版本 gdal 3.8.3
参考博客:https://www.cnblogs.com/echohye/p/17580078.html
1. 下载源码
version=3.8.3
wget http://download.osgeo.org/gdal/$version/gdal-$version.tar.xz
2. 编译。解压,执行:
cmake -S . -B build \
-DCMAKE_INSTALL_RPATH=/opt/gdal \
-DBUILD_JAVA_BINDINGS=ON \
-DCMAKE_INSTALL_PREFIX=/opt/gdal \
-DCMAKE_INSTALL_LIBDIR=/opt/gdal \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_VERBOSE_MAKEFILE=ON \
-Wno-dev \
-DBUILD_TESTING=OFF
这一步会报错,提示:
Buildfile: /Users/xxxx/Downloads/temp3/gdal-3.8.3/swig/java/build.xml
init:
[echo] version = 3.8.3
compile:
[mkdir] Created dir: /Users/xxxx/Downloads/temp3/gdal-3.8.3/build/swig/java/build/classes
[javac] Compiling 88 source files to /Users/xxxx/Downloads/temp3/gdal-3.8.3/build/swig/java/build/classes
[javac] 警告: [options] 未与 -source 7 一起设置引导类路径
[javac] 错误: 不再支持源选项 7。请使用 8 或更高版本。
[javac] 错误: 不再支持目标选项 7。请使用 8 或更高版本。
BUILD FAILED
/Users/xxxx/Downloads/temp3/gdal-3.8.3/swig/java/build.xml:25: Compile failed; see the compiler error output for details.
3. 修正编译错误
这时候只需要修改下/Users/xxxx/Downloads/temp3/gdal-3.8.3/swig/java/build.xml:
将里面的两处 source="7" target="7" 改为 source="8" target="8" 即可。
4. 安装。
然后安装库:cmake --build build
如果有权限问题,就加sudo。
5. 拷贝产物。
最后再把 /opt/gdal/jni下的 libgdalalljni.dylib 复制到/Library/Java/Extensions里就行了。
可能还需要把 /opt/gdal/下的libgdal.dylib 等文件也复制过去
如果 /opt/gdal/jni 下没有产物,可以看看 /Users/xxxx/Downloads/temp3/gdal-3.8.3/build 和 /Users/xxxx/Downloads/temp3/gdal-3.8.3/build/swig/java 下。
@zty5678
Copy link
Author

zty5678 commented May 13, 2025

最新编译脚本(3.8.3):
编译报错:
/temp3/gdal-3.8.3/frmts/pdf/pdfdataset.cpp:3796:12: error: cannot initialize a variable of type 'Array ' with an rvalue of type 'const Array '
3796 | Array *array = optContentConfig->getOrderArray();
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

于是修改了编译脚本:

cmake -S . -B build
-DCMAKE_INSTALL_RPATH=/opt/gdal
-DBUILD_JAVA_BINDINGS=ON
-DCMAKE_INSTALL_PREFIX=/opt/gdal
-DCMAKE_INSTALL_LIBDIR=/opt/gdal
-DCMAKE_DISABLE_FIND_PACKAGE_Arrow=ON
-DCMAKE_BUILD_TYPE=Release
-DGDAL_USE_LIBKML=OFF
-DCMAKE_VERBOSE_MAKEFILE=ON
-Wno-dev
-DBUILD_TESTING=OFF
-DCMAKE_CXX_STANDARD=20
-DGDAL_ENABLE_DRIVER_PDF=OFF
-DGDAL_ENABLE_DRIVER_NETCDF=OFF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment