[gdal-dev] Compile GDAL with swig(Java) on MAC OS X

William Kyngesburye woklist at kyngchaos.com
Tue Dec 6 10:24:04 EST 2011


On Dec 6, 2011, at 4:40 AM, Even Rouault wrote:

> Dennis,
> 
>> 
>> This works well so far, but the libgdaljni.dylib is directly linked to
>> libgdal in the base Folder. So, if copy my program to another location,
>> I will get a UnsatisfiedLinkError.
> 
> Yes, both libs must be accessible through the java.library.path property (or in
> a system library directory, or in LD_LIBRARY_PATH if this works on MacOSX)
> 
It's DYLD_LIBRARY_PATH on OS X.

But, that's the way OS X linking works - the full path to the library is coded into the binary.  If you don't want to mess with DYLD_LIBRARY_PATH or java.library.path, you can use install_name_tool to change where it looks for GDAL.  You need to run otool on the jni library first to see where it's currently looking for gdal.

otool -L /path/to/libgdaljni.dylib

[copy path to libgdal.dylib]

install_name_tool -change /current/path/to/libgdal.dylib /new/path/to/libgdal.dylib /path/to/libgdaljni.dylib


I thought I had instructions to add the java interface to my GDAL framework, but that was for Mapserver.  An interesting test would be to compile GDAL + plus java as you've done (make sure it's v1.8.1), then instead of relinking it to a different libgdal location, relink it to my GDAL framework binary:

install_name_tool -change /current/path/to/libgdal.dylib /Library/Frameworks/GDAL.framework/Versions/1.8/GDAL /path/to/libgdaljni.dylib

Success depends on if the java compilation hardwires in configured formats (bad) or depends on the GDAL library for that info (good), and if the support folder path is compiled in (bad) or it gets it from the GDAL library (good).

-----
William Kyngesburye <kyngchaos*at*kyngchaos*dot*com>
http://www.kyngchaos.com/

"Mon Dieu! but they are all alike.  Cheating, murdering, lying, fighting, and all for things that the beasts of the jungle would not deign to possess - money to purchase the effeminate pleasures of weaklings.  And yet withal bound down by silly customs that make them slaves to their unhappy lot while firm in the belief that they be the lords of creation enjoying the only real pleasures of existence....

- the wisdom of Tarzan




More information about the gdal-dev mailing list