[Rxtx] JNI 32 vs 64 bit issues

Ivan Maidanski ivmai at mail.ru
Tue Mar 16 11:36:27 MDT 2010


Tue, 16 Mar 2010 10:31:23 -0700 letter from Nick Sayer <nsayer at kfu.com>:

> So in the 2.2-pre-2 version of rxtx, the loadLibrary step for rxtxSerial is a simple
> 
> loadLibrary("rxtxSerial")
> 
> This causes problems on Linux and Windows if you want to support 32 and 64 bit architectures simultaneously.

This was already discussed in this ML. Fetch the latest rxtx CVS.

> 
> For one thing, os.arch on Windows is the same for 32 and 64 bits. What you're supposed to do is check the value of the "sun.arch.data.model" property for 32 vs 64 bit. This fails utterly, however, in JNLP files, since the only thing you can check against is os.name and os.arch - meaning you can only have one native lib jar, which will need to contain separate 32 and 64 bit DLLs if you want to support both.
> 
> For Linux, you also need separate 32 and 64 bit .so files, but they both need to have the same name (lilbrxtxSerial.so). This means that they need to be kept in separate directories and a script needs to set java.library.path as appropriate for the local architecture. This is a pain in the neck.
> 
> The fix is to change the call to loadLibrary like this:
> 
> boolean is64bit = System.getProperty("sun.arch.data.model").contains("64");
> 
> try {
> 	System.loadLibrary("rxtxSerial-" + (is64bit?"64":"32"));
> }
> catch(UnsatisfiedLinkException ex) {
> 	System.loadLibrary("rxtxSerial");
> }
> 
> This will attempt to load a specific data-model DLL/so file for those platforms where it is required (Windows and Linux), but will fall back to attempting to load a non-specific one for platforms that don't (like MacOS X, where the jnilib can be a universal binary for all 3 architectures).
> 
> There are 3 calls to load rxtxSerial in the code. The calls in RXTXCommDriver and RXTXPort probably should be removed and replaced by some sort of check against RXTXVersion, which would do the loading. But there probably ought to be some sort of static utility method somewhere to load the other libraries (I2C, Parallel, RS485, Raw and Zystem) using this same methodology.
> 
> _______________________________________________
> Rxtx mailing list
> Rxtx at qbang.org
> http://mailman.qbang.org/mailman/listinfo/rxtx
> 



More information about the Rxtx mailing list