473,387 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

JNI (C++ calls from Java)

Hi,

I'm working on an application which requires some native calls to be
made from Java. The calls work fine in one version of my code. I need
to change the location of my native calls to a different file but when
I move them to another native file I receive the following error. I've
included all .h includes and path locations (LD_LIBRARY_PATH) and the
build script contains the libraries required to run.

The strange thing: I removed the problematic 'readFrame' method from my
native code and still receive the same error...

java.lang.UnsatisfiedLinkError:
/home/delboy/acemedia/var/osgi/fwdir/bs/9/jar0/librvacetoolbox.so:
/home/delboy/acemedia/var/osgi/fwdir/bs/9/jar0/librvacetoolbox.so:
undefined symbol: _Z9readFramei
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.jav a:1751)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java :1660)
at java.lang.Runtime.loadLibrary0(Runtime.java:822)
at java.lang.System.loadLibrary(System.java:993)

Could this be a case of mangled C++ symbols?

Any suggestions would be great,

Del

Dec 7 '06 #1
4 4866
On 7 Dec 2006 08:56:00 -0800 in comp.lang.c++, th************@gmail.com
wrote,
java.lang.UnsatisfiedLinkError:
undefined symbol: _Z9readFramei
>Could this be a case of mangled C++ symbols?
Seems like it could be... without knowing JNI, I guess that Z9readFramei
must be declared with the
extern "C"
linkage attribute in the C++ code. Is that true?

Dec 7 '06 #2
On Thu, 07 Dec 2006 17:11:53 +0000, David Harmon wrote:
On 7 Dec 2006 08:56:00 -0800 in comp.lang.c++, th************@gmail.com
wrote,
>java.lang.UnsatisfiedLinkError:
undefined symbol: _Z9readFramei
>>Could this be a case of mangled C++ symbols?

Seems like it could be... without knowing JNI, I guess that Z9readFramei
must be declared with the
extern "C"
linkage attribute in the C++ code. Is that true?
You are correct.

Things you want to export from c++ must be defined
extern "C" so the names make sense to the foreign environment.

Dec 8 '06 #3
noone schrieb:
On Thu, 07 Dec 2006 17:11:53 +0000, David Harmon wrote:
>On 7 Dec 2006 08:56:00 -0800 in comp.lang.c++, th************@gmail.com
wrote,
>>java.lang.UnsatisfiedLinkError:
undefined symbol: _Z9readFramei
Could this be a case of mangled C++ symbols?
Seems like it could be... without knowing JNI, I guess that Z9readFramei
must be declared with the
extern "C"
linkage attribute in the C++ code. Is that true?

You are correct.

Things you want to export from c++ must be defined
extern "C" so the names make sense to the foreign environment.
Hej,

This should be done automatically if you used the "javah" to generate
the C++ header file.

I compiled a .java file containing the line
public native float makefloat( byte a, byte b, byte c, byte d );

and javah's output was:
#include <jni.h>
....
#ifdef __cplusplus
extern "C" {
#endif
....
JNIEXPORT jfloat JNICALL Java_connectivity_UdpConverter_makefloat
(JNIEnv *, jobject, jbyte, jbyte, jbyte, jbyte);

#ifdef __cplusplus
}
#endif

and in the appropriate cpp file I just implemented that method:

JNIEXPORT jfloat JNICALL Java_connectivity_UdpConverter_makefloat
(JNIEnv *env, jobject obj, jbyte byte1, jbyte byte2, jbyte byte3,
jbyte byte4)
{
....
}

The result project type is a dll which is loaded from the java file with:

static
{
System.loadLibrary( "ConvertByteArrayToFloat" );
}
before the first call.

I used that book
@book{Gor98,
author = {Gordon, Rob},
title = {{Essential JNI: Java Native Interface}},
edition = {1st},
publisher = {Prentice Hall Inc.},
address = {NJ, USA},
year = {1998}
}
for JNI help, and it is extremely well (and funny) written and I can
recommend it; you may want to look for a newer release, though.

Jan
Dec 8 '06 #4
Hi Jan,

That's correct...the auto generated header wraps extern "C" around the
JNIExport declarations.
Out of curiousity, I also added the extern "C" to my native code and it
seems to have made some progress (if you can call it that), I'm now
getting a similar error on a different function name...I was getting
tired of the old one anyway.

The new error looks like:

java.lang.UnsatisfiedLinkError:
/home/delboy/acemedia/var/osgi/fwdir/bs/9/jar0/librvacetoolbox.so:
/home/delboy/acemedia/var/osgi/fwdir/bs/9/jar0/librvacetoolbox.so:
undefined symbol: checkFileExists
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.jav a:1751)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java :1660)
at java.lang.Runtime.loadLibrary0(Runtime.java:822)
at java.lang.System.loadLibrary(System.java:993)

I also tried using the linux ldd command but didn't find anything out
of place. I got my hands on a copy of Rob Gordon's book, it's currently
sitting on my desk but I intend to start reading soon...

Del

Jan Bornschlegel wrote:
noone schrieb:
On Thu, 07 Dec 2006 17:11:53 +0000, David Harmon wrote:
On 7 Dec 2006 08:56:00 -0800 in comp.lang.c++, th************@gmail.com
wrote,
java.lang.UnsatisfiedLinkError:
undefined symbol: _Z9readFramei
Could this be a case of mangled C++ symbols?
Seems like it could be... without knowing JNI, I guess that Z9readFramei
must be declared with the
extern "C"
linkage attribute in the C++ code. Is that true?
You are correct.

Things you want to export from c++ must be defined
extern "C" so the names make sense to the foreign environment.

Hej,

This should be done automatically if you used the "javah" to generate
the C++ header file.

I compiled a .java file containing the line
public native float makefloat( byte a, byte b, byte c, byte d );

and javah's output was:
#include <jni.h>
...
#ifdef __cplusplus
extern "C" {
#endif
...
JNIEXPORT jfloat JNICALL Java_connectivity_UdpConverter_makefloat
(JNIEnv *, jobject, jbyte, jbyte, jbyte, jbyte);

#ifdef __cplusplus
}
#endif

and in the appropriate cpp file I just implemented that method:

JNIEXPORT jfloat JNICALL Java_connectivity_UdpConverter_makefloat
(JNIEnv *env, jobject obj, jbyte byte1, jbyte byte2, jbyte byte3,
jbyte byte4)
{
...
}

The result project type is a dll which is loaded from the java file with:

static
{
System.loadLibrary( "ConvertByteArrayToFloat" );
}
before the first call.

I used that book
@book{Gor98,
author = {Gordon, Rob},
title = {{Essential JNI: Java Native Interface}},
edition = {1st},
publisher = {Prentice Hall Inc.},
address = {NJ, USA},
year = {1998}
}
for JNI help, and it is extremely well (and funny) written and I can
recommend it; you may want to look for a newer release, though.

Jan
Dec 8 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Linus Nikander | last post by:
After trying to manually reverse-engineer a piece of code i've been handed using Visio I figure someone must have developed a tool that can do automatically in 5 minutes what took me 2 hours. ...
1
by: Steve W | last post by:
I've searched over and over again and have not been able to find a definitive answer. Basically, we have a heavily JavaScripted web site. What I was hoping to do was to start enhancing our site...
0
by: Chris Thiessen | last post by:
Kataba Functions is a library for Java which provides: - Super-Fast Reflective and Dynamic Calls - Next to as fast as an interface call. Up to 100 X faster than reflection. In fact, through...
10
by: Michael | last post by:
Guys, I'm interested in how the compiler implements function calls, can anyone correct my understanding/point me towards some good articles. When a function is called, is the stack pointer...
7
by: Dima | last post by:
Call to XmlNode.GetElementsByTagName returns XmlNodeList that stays in sync with XmlDocument thanks to events fired by XmlDocument. Once this list is created there is no way to remove its event...
2
by: Deepak | last post by:
Hi, is there a way to call Sun Java code from C# code ? I have seen a way that is posted somewhere on the web that says to use System command to spawn a DOS window and then pass a string to this...
6
by: Dasn | last post by:
Hi, there. 'lines' is a large list of strings each of which is seperated by '\t' I wanna split each string into a list. For speed, using map() instead of 'for' loop. 'map(str.split, lines)'...
0
by: Nova | last post by:
Hi, I created a Java UDF (PARAMETER STYLE JAVA) for DB2 9 Express-C. I finally does what I want it to do. However, after a few hundred calls to the UDF, it fails and raises an SQL error,...
0
by: TraceyAnnison | last post by:
I wonder if you can help me - I'm new to this, and working in a project that has already been configured to work with Axis. We have a Java project built with the Spring framework, in order to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.