How to compile java gdal PGEO on apple silicon MacOS to read mdb file?

27 Views Asked by At

I installed unixodbc and mdbtools through Homebrew, and all dependences of gdal.

my cmake configure is following:

cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/Users/yuziqun/main/software/gdal-3.8.4-nokml -DCMAKE_INSTALL_RPATH=/Users/yuziqun/main/software/gdal-3.8.4-nokml/lib -DBUILD_PYTHON_BINDINGS=OFF -DGDAL_USE_LIBKML=OFF -DCMAKE_DISABLE_FIND_PACKAGE_Arrow=ON -DPGEO_DRIVER_TEMPLATE="DRIVER=Microsoft Access Driver (*.mdb);DBQ=%s" ..

and I get some information and one warning:

➜  gdal-3.8.4 mkdir build
➜  gdal-3.8.4 cd build
➜  build cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/Users/yuziqun/main/software/gdal-3.8.4-nokml -DCMAKE_INSTALL_RPATH=/Users/yuziqun/main/software/gdal-3.8.4-nokml/lib -DBUILD_PYTHON_BINDINGS=OFF -DGDAL_USE_LIBKML=OFF -DCMAKE_DISABLE_FIND_PACKAGE_Arrow=ON -DPGEO_DRIVER_TEMPLATE="DRIVER=Microsoft Access Driver (*.mdb);DBQ=%s" ..
...
...
-- Found ODBC: /opt/homebrew/lib/libodbc.dylib  found components: ODBCINST
...
...
-- Configuring done (16.1s)
-- Generating done (0.8s)
CMake Warning:
  Manually-specified variables were not used by the project:

    PGEO_DRIVER_TEMPLATE


-- Build files have been written to: /Users/yuziqun/main/temp/gdal-3.8.4/build
➜  build cmake --build . -- -j6
➜  build cmake --build . --target install

I don't know why the PGEO_DRIVER_TEMPLATE is not used.

Then I copied libgdalalljni.dylib and placed it in /Library/Java/extensions.

Then I get an error while running a Java program:

gdal.AllRegister();
System.out.println(gdal.VersionInfo());
Driver driver = ogr.GetDriverByName("PGeo");
DataSource ds = driver.Open("/Users/yuziqun/main/temp/640122HLX_2006Y00_SV050_P.mdb", 0);
System.out.println(ds);
3080400
ERROR 3: Cannot open file '/etc/odbcinst.ini'
ERROR 1: ODBC: MDB Tools driver not found!

ERROR 1: Unable to initialize ODBC connection to DSN for /Users/yuziqun/main/temp/640122HLX_2006Y00_SV050_P.mdb,

null

Then I went to find odbcinst.ini. In the end, I copied odbcinst.ini and odbc.ini from the /opt/homebrew/etc directory to the /etc directory, and edited the odbcinst.ini file as follows:

[Microsoft Access Driver (*.mdb)]
Description = MDB Tools ODBC drivers
Driver     = /opt/homebrew/lib/libmdb.dylib
Setup      = /opt/homebrew/lib/libmdb.dylib
FileUsage  = 1
CPTimeout  =
CPReuse    =

But I still got an error:

3080400
ERROR 1: Unable to initialize ODBC connection to DSN for /Users/yuziqun/main/temp/640122HLX_2006Y00_SV050_P.mdb,

null

I want to know which step I made an error in, could you please help me.

I have tried many methods, and I hope my program can run normally. I hope I haven't missed any details from the official document :) .

0

There are 0 best solutions below