JNA Download Libraries

I have two libraries, one with Ada objects and one with C ++ objects (I don't have much control over what happens)

Ada's material refers to material C and vice versa ...

This symbol is located in libIPCAda.so: ipc_manager_shutdown_c

This symbol is in libIPCC.so: stream_buffer_header_size

When I make these JNA calls:

CLibrary INSTANCE8 = (CLibrary) Native.loadLibrary("IPCAda", // <<< our library goes here CLibrary.class); CLibrary INSTANCE9 = (CLibrary) Native.loadLibrary("IPCC", // <<< our library goes here CLibrary.class); 

I get this:

 ld.so.1: java: fatal: relocation error: file <<my directory>>/lib/libIPCAda.so: symbol stream_buffer_header_size: referenced symbol not found 

When I make these JNA calls:

  CLibrary INSTANCE9 = (CLibrary) Native.loadLibrary("IPCC", // <<< our library goes here CLibrary.class); CLibrary INSTANCE8 = (CLibrary) Native.loadLibrary("IPCAda", // <<< our library goes here CLibrary.class); 

I get this:

 Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'IPCC': ld.so.1: java: fatal: relocation error: file <<my directory>>/lib/libIPCC.so: symbol ipc_manager_shutdown_c: referenced symbol not found at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:163) at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:236) at com.sun.jna.Library$Handler.<init>(Library.java:140) at com.sun.jna.Native.loadLibrary(Native.java:379) at com.sun.jna.Native.loadLibrary(Native.java:364) at Test2$CLibrary.<clinit>(Test2.java:55) at Test2.main(Test2.java:74) 

Obviously, he doesn't like the cross-shaped characters ... Is there a way to make this work in JNA?

* IMAGE Compilation example *

 gcc -c -fPIC -g -O0 -fstack-check -pipe -gnatE -gnatU -gnatwl -gnatf -gnatE -gnat05 -lIPCC -I- -gnatA <<my directory>>src/ndds_c.adb 
+7
source share
2 answers

Crossbreeding will occur in native code, not inside Java. As JNA knows, it downloads two completely independent native libraries.

You must provide the libraries with each other yourself. There are several ways to do this; either set rpath when compiling the shared library, or set the LD_LIBRARY_PATH environment variable at run time.

Rpath is arguably the best method because it is specific to the binary file it needs and does not pollute the runtime. You can install it in gcc with the following compiler flags:

-Lpath-to-your-library -Wl,-rpath,path-to-your-library

+6
source

Do you put ALL of your own keywords in one "library"? Therefore, when he does the first Native.loadLibrary, he tries to match all the characters from the first uploaded file to all your Native specific methods.

Try splitting it into CLibrary1 and CLibrary2, where they exactly correspond to the symbol that will be loaded by the Ada and C libraries. I believe that Java will try to display all your own methods and will work with half that is missing in the first Native.loadLibrary.

 CLibrary INSTANCE9 = (CLibrary) Native.loadLibrary("IPCC", // <<< our library goes here CLibrary.class); AdaLibrary INSTANCE8 = (AdaLibrary) Native.loadLibrary("IPCAda", // <<< our library goes here AdaLibrary.class); 

You also mention C ++. Java JNI cannot load C ++ garbled characters. If you might have forced the implementation to export as C characters, you'll be fine. Do not exchange C and C ++ when talking about your own implementations.

+1
source

All Articles