Error trying to load compiled c code

51 views
Skip to first unread message

Erick Moreno

unread,
Sep 20, 2012, 8:59:45 AM9/20/12
to jna-...@googlegroups.com
Hi All,

I'm completely newbie in JNA and I confess that I don't know a lot about C programming. But I'm trying to map com calls from a c software compiled by me and I'm having some troubles.

I'm quite sure that I'm passing correct path to the software using
-Djna.library.path=/root/voicerlib/voicerlib-4.2.4.0/src_common/  parameter but I'm still receiving the java.lang.UnsatisfiedLinkError error.

The first thing that I notice is that I'm using "voicerlib" as lib name (since I believe that this is the real name of the lib). But JNA is looking for a libvoicerlib.so file that doesn't exists.

- So, why is JNA adding the 'lib' prefix to the name file?
- And, why is JNA looking for a .so extension? Can a configure to look for just a .c file?

The full stack to the error is following.

~ java -jar sis-placa-null.jar -Djna.library.path=/root/voicerlib/voicerlib-4.2.4.0/src_common/
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'voicerlib': libvoicerlib.so: cannot open shared object file: No such file or directory
    at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:169)
    at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:242)
    at com.sun.jna.Library$Handler.<init>(Library.java:140)
    at com.sun.jna.Native.loadLibrary(Native.java:368)
    at com.sun.jna.Native.loadLibrary(Native.java:353)
    at br.gov.dpf.sis.placa.VoicerLibWrapper.<clinit>(VoicerLibWrapper.java:8)
    at br.gov.dpf.sis.placa.SISCallMonitor.main(SISCallMonitor.java:6)



Thanks in advance!


Timothy Wall

unread,
Sep 20, 2012, 12:48:37 PM9/20/12
to jna-...@googlegroups.com

On Sep 20, 2012, at 8:59 AM, Erick Moreno wrote:

> Hi All,
>
> I'm completely newbie in JNA and I confess that I don't know a lot about C programming. But I'm trying to map com calls from a c software compiled by me and I'm having some troubles.

If you understand what "compiled" means, then you wouldn't be asking if JNA should look for a .c file. JNA can load a shared library, which is built from source files in a special way, into a file called libXXXX.so, where XXXX is the "name" of your library.

>
> I'm quite sure that I'm passing correct path to the software using
> -Djna.library.path=/root/voicerlib/voicerlib-4.2.4.0/src_common/ parameter but I'm still receiving the java.lang.UnsatisfiedLinkError error.
>
> The first thing that I notice is that I'm using "voicerlib" as lib name (since I believe that this is the real name of the lib). But JNA is looking for a libvoicerlib.so file that doesn't exists.
>
> - So, why is JNA adding the 'lib' prefix to the name file?
> - And, why is JNA looking for a .so extension? Can a configure to look for just a .c file?

Read the documentation on how JNA maps a library "name" into an actual filename. What is the name of the file of the library you're trying to load? Whether you built it yourself or downloaded a package, it's not likely to be found in src_common.

When you call Native.loadLibrary(), you can always pass an absolute path to the file you want to load.

Erick Moreno

unread,
Sep 24, 2012, 2:09:30 PM9/24/12
to jna-...@googlegroups.com
Hi Timothy,

Sorry, but I know what compiled means, I just swapped the right file extension I was talking about ( .o ).

Btw, you answered my question, I run an gcc -shared -o libvoicerlib.so ... command and build myself a lib, since the "lib" provider don't deliver a .so file. I believe that this solved my problems.

Now I'm curious to know, where the hell in the documentation is something about "how JNA maps a library "name" into an actual filename" ?

Thanks.

Kustaa Nyholm

unread,
Sep 24, 2012, 2:53:02 PM9/24/12
to jna-...@googlegroups.com
On 24.9.2012 21.09, "Erick Moreno" <erick...@gmail.com> wrote:
>
>Now I'm curious to know, where the hell in the documentation is something
>about "how JNA maps a library "name" into an actual filename" ?


I googled for:

jna javadoc

which lead me to this:

http://jna.java.net/javadoc/overview-summary.html

and there under 'Library Mapping' it is spelled out.

br Kusti

Daniel Doubrovkine

unread,
Sep 24, 2012, 3:07:16 PM9/24/12
to jna-...@googlegroups.com
Fyi, JavaDoc is linked from the README and lives in http://twall.github.com/jna/3.4.1/javadoc/ for 3.4.1.
--

dB. | Moscow - Geneva - Seattle - New York
dblock.org - @dblockdotorg


Reply all
Reply to author
Forward
0 new messages