java - JNA code working fine in OSx , but unable to lookup function in Linux from C shared object file -
i working following example: https://github.com/caplin/jnijnaexamples/tree/master/jna
in mac, create .dylib file follows:
gcc -shared -fpic -o librandomjna.o randomjna.c
g++ -dynamiclib -undefined suppress -flat_namespace *.o -o librandomjna.dylib
mkdir classes
javac -d classes -classpath jna-4.4.0.jar javanativeaccess.java
cd classes
export ld_library_path=.
java -classpath jna-4.4.0.jar:. com.enlightedinc.apps.where.utils.javanativeaccess
in osx, works expected , able execute c function list_files
now in linux box, created .so file follows
gcc -shared -fpic -o librandomjna.o randomjna.c
gcc -shared -o librandomjna.so *.o
in same way, new classes generated in linux mkdir classes
javac -d classes -classpath jna-4.4.0.jar javanativeaccess.java
cd classes
export ld_library_path=.
java -classpath jna-4.4.0.jar:. com.enlightedinc.apps.where.utils.javanativeaccess
now when try execute code in ubuntu box, following error exceptionjava.lang.unsatisfiedlinkerror: error looking function 'randomnumber': ./librandomjna.so: undefined symbol: randomnumber
- what can possibly go wrong ?
- whats difference between .dylib , .so file ?
- why .dylib (mac osx) can resolve function calls , whereas .so file (linux) fails function ?
any highly appreciated.
thanks kaniska
first of all, try following:
export ld_library_path=${ld_library_path}:.
then, make sure file contains expect
nm librandomjna.so | grep rand
Comments
Post a Comment