CC: [EMAIL PROTECTED]
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
subject: =
"Undefined symbols" errors when System.loadLibrary is loading shared obje=
ct
file
1. synopsis of the problem
------------------------- HelloWorld.java ------------------------------=
import java.lang.*;
class HelloWorld {
public native void displayHelloWorld( int cce);
static {
System.loadLibrary("hello");
}
public static void main(String[] args) {
new HelloWorld().displayHelloWorld( 9090);
}
}
------------------------- HelloWorld.java ------------------------------=
%javac HelloWorld.java =
%javah -jni HelloWorld =
------------------------- HelloWorld.h ------------------------------
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class HelloWorld */
#ifndef _Included_HelloWorld
#define _Included_HelloWorld
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: HelloWorld
* Method: displayHelloWorld
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld
(JNIEnv *, jobject, jint);
#ifdef __cplusplus
}
#endif
#endif
------------------------- HelloWorld.h ------------------------------
------------------------- HelloWorldImp.c ------------------------------=
//#include <jni.h>
#include "HelloWorld.h"
#include <stdio.h>
JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj, jint cce)
{
printf("%d Hello world!\n", cce);
return;
}
------------------------- HelloWorldImp.c ------------------------------=
%gcc -g -shared -I/usr/include -I/usr/share/jdk1.1.6/include \
-I/usr/share/jdk1.1.6/include/genunix HelloWorldImp.c -o libhello=
=2Eso =
LD_LIBRARY_PATH=3D.:/usr/lib:/usr/local/lib:/usr/share/jdk1.1.6/lib:/usr/=
share/jdk1.1.6/lib/i686/green_threads
%java HelloWorld
9090 Hello world!
However if i change the above code to:
------------------------- HelloWorld2.java ------------------------------=
import java.lang.*;
public class HelloWorld2 {
public native void displayHelloWorld( int cce);
public native void displayFileDetails( String fileName );
static {
System.loadLibrary("hello");
}
public static void main(String[] args) {
new HelloWorld2().displayHelloWorld( 9090);
new HelloWorld2().displayFileDetails(
"/home/seshu/temp.html");
}
}
------------------------- HelloWorld2.java ------------------------------=
%javac HelloWorld2.java
%javah -jni HelloWorld2
------------------------- HelloWorld2.h ------------------------------
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class HelloWorld2 */
#ifndef _Included_HelloWorld2
#define _Included_HelloWorld2
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: HelloWorld2
* Method: displayHelloWorld
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_HelloWorld2_displayHelloWorld
(JNIEnv *, jobject, jint);
/*
* Class: HelloWorld2
* Method: displayFileDetails
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_HelloWorld2_displayFileDetails
(JNIEnv *, jobject, jstring);
#ifdef __cplusplus
}
#endif
#endif
------------------------- HelloWorld2.h ------------------------------
------------------------- HelloWorldImp2.c ------------------------------=
//#include <jni.h>
#include "HelloWorld2.h"
#include <stdio.h>
JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj, jint cce)
{
printf("%d Hello world!\n", cce);
return;
}
JNIEXPORT void JNICALL
Java_HelloWorld_displayFileDetails(JNIEnv *env, jobject obj, jstring name=
)
{
const char *_fileName =3D (*env)->GetStringUTFChars(env, name , 0 );
struct stat * nodeStat;
char *_lastAccessed =3D (char *) malloc (30 * sizeof(char));
char *_lastModified =3D (char *) malloc (30 * sizeof(char));
char *_lastChanged =3D (char *) malloc (30 * sizeof(char));
lstat( _fileName , nodeStat);
strncpy ( _lastAccessed , ctime( &nodeStat->st_atime ), 24 );
strncpy ( _lastModified , ctime( &nodeStat->st_mtime ), 24 );
strncpy ( _lastChanged , ctime( &nodeStat->st_ctime ), 24 );
printf( "%s %s %s %s %10ld\n" , _fileName, _lastAccessed, _lastModified=
,
_lastChanged, nodeStat->st_size);
(*env)->ReleaseStringUTFChars(env, name , _fileName);
return;
}
------------------------- HelloWorldImp2.c ------------------------------=
%gcc -g -shared -I/usr/include -I/usr/share/jdk1.1.6/include
-I/usr/share/jdk1.1.6/include/genunix HelloWorldImp2.c -o libhello.so
%java HelloWorld2
=2E/libhello.so: undefined symbol: lstat (libhello.so)
Can't find class HelloWorld2
again the =
LD_LIBRARY_PATH=3D.:/usr/lib:/usr/local/lib:/usr/share/jdk1.1.6/lib:/usr/=
share/jdk1.1.6/lib/i686/green_threads
--------------------------------------------------------------------
here is what i saw by using nm
%nm libhello.so | more =
000004b4 T Java_HelloWorld_displayFileDetails
00000498 T Java_HelloWorld_displayHelloWorld
00001690 A _DYNAMIC
00001670 A _GLOBAL_OFFSET_TABLE_
00001664 ? __CTOR_END__
00001660 ? __CTOR_LIST__
0000166c ? __DTOR_END__
00001668 ? __DTOR_LIST__
U ___brk_addr
00001710 A __bss_start
000005bc t __do_global_ctors_aux
0000044c t __do_global_dtors_aux
U __environ
U __gmon_start__
00001710 A _edata
00001710 A _end
0000061c A _etext
00000620 ? _fini
000003f0 ? _init
U atexit
U ctime
00000480 t fini_dummy
00001660 d force_to_data
00001660 d force_to_data
0000044c t gcc2_compiled.
000005bc t gcc2_compiled.
0000061c t gcc2_compiled.
0000044c t gcc2_compiled.
000005f0 t init_dummy
U lstat
U malloc
U printf
U strncpy
--------------------------------------------------------------------
but if I compile in the same environment (i mean without disturbing =
LD_LIBRARY_PATH, PATH etc...)
------------------------- myhello.c ------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <ustat.h>
#include <errno.h>
#include <time.h>
int main( int argc , char *argv[] ) {
char *_fileName =3D (char *) malloc(100* sizeof(char));
char *_lastAccessed =3D (char *) malloc (30 * sizeof(char));
char *_lastModified =3D (char *) malloc (30 * sizeof(char));
char *_lastChanged =3D (char *) malloc (30 * sizeof(char));
struct stat * nodeStat =3D (struct stat *) malloc ( sizeof(struct stat)=
);
_fileName =3D strcpy( _fileName , "/home/seshu/temp.html");
lstat( _fileName , nodeStat);
strncpy ( _lastAccessed , ctime( &nodeStat->st_atime ), 24 );
strncpy ( _lastModified , ctime( &nodeStat->st_mtime ), 24 );
strncpy ( _lastChanged , ctime( &nodeStat->st_ctime ), 24 );
printf( "%s %s %s %s %10ld\n" , _fileName, _lastAccessed, _lastModified=
,
_lastChanged, nodeStat->st_size);
return 1;
}
------------------------- myhello.c ------------------------------
=
%gcc -g -I/usr/include myhello.c -o myhello
%./myhello =
/home/seshu/temp.html Tue Sep 15 18:09:52 1998 Tue Sep 15 18:08:58 1998 T=
ue
Sep 15 18:08:59 1998 4161
which works perfect....
now i am not able to understand what the hell is wrong with =
System.loadLibrary("hello");
that it is throwing errors in the second case.
2. java version "Linux_JDK_1.1.6_v1"
3. RedHat Linux 5.1 =
4. ldconfig -D 2>&1 | grep libc
----------------------------------------------------------------
ldconfig: warning: /usr/i486-linux-libc5/lib/libform.so.1.9.9e has
inconsistent soname (libform.so.3.0)
ldconfig: warning: /usr/i486-linux-libc5/lib/libmenu.so.1.9.9e has
inconsistent soname (libmenu.so.3.0)
ldconfig: warning: /usr/i486-linux-libc5/lib/libncurses.so.1.9.9e has
inconsistent soname (libncurses.so.3.0)
ldconfig: warning: /usr/i486-linux-libc5/lib/libpanel.so.1.9.9e has
inconsistent soname (libpanel.so.3.0)
libcurses.so.0 =3D> libcurses.so.0.1.2
libc.so.4 =3D> libc.so.4.7.2
libcrack.so.2 =3D> libcrack.so.2.7
/usr/i486-linux-libc5/lib:
libc.so.5 =3D> libc.so.5.3.12
ldconfig: warning: /lib/libc-2.0.7.so has inconsistent soname (libc.so.6)=
ldconfig: warning: /lib/libcrypt-2.0.7.so has inconsistent soname
(libcrypt.so.1)
libcrack.so.2 =3D> libcrack.so.2.7
libcom_err.so.2 =3D> libcom_err.so.2.0
libcrypt.so.1 =3D> libcrypt-2.0.7.so
libc.so.6 =3D> libc-2.0.7.so
----------------------------------------------------------------
5. ldconfig -D 2>&1 | grep ld =
----------------------------------------------------------------
ldconfig: warning: can't open 2 (No such file or directory), skipping
ldconfig: warning: /usr/lib/libnewt.so.0.25 has inconsistent soname
(libnewt.so.0.20)
ldconfig: warning: /usr/i486-linux-libc5/lib/libform.so.1.9.9e has
inconsistent soname (libform.so.3.0)
ldconfig: warning: /usr/i486-linux-libc5/lib/libmenu.so.1.9.9e has
inconsistent soname (libmenu.so.3.0)
ldconfig: warning: /usr/i486-linux-libc5/lib/libncurses.so.1.9.9e has
inconsistent soname (libncurses.so.3.0)
ldconfig: warning: /usr/i486-linux-libc5/lib/libpanel.so.1.9.9e has
inconsistent soname (libpanel.so.3.0)
ldconfig: warning: /usr/lib/libnewt.so.0.25 has inconsistent soname
(libnewt.so.0.20)
ldconfig: version 970402
libpng.so.2 =3D> libpng.so.2ldconfig: warning: /lib/ld-2.0.7.so h=
as
inconsistent soname (ld-linux.so.2)
ldconfig: warning: /lib/libBrokenLocale-2.0.7.so has inconsistent soname
(libBrokenLocale.so.1)
ldconfig: warning: /lib/libc-2.0.7.so has inconsistent soname (libc.so.6)=
ldconfig: warning: /lib/libcrypt-2.0.7.so has inconsistent soname
(libcrypt.so.1)
ldconfig: warning: /lib/libdb-2.0.7.so has inconsistent soname (libdb.so.=
2)
ldconfig: warning: /lib/libdl-2.0.7.so has inconsistent soname (libdl.so.=
2)
ldconfig: warning: /lib/libm-2.0.7.so has inconsistent soname (libm.so.6)=
ldconfig: warning: /lib/libnsl-2.0.7.so has inconsistent soname (libnsl.s=
o.1)
ldconfig: warning: /lib/libnss_compat-2.0.7.so has inconsistent soname
(libnss_compat.so.1)
ldconfig: warning: /lib/libnss_db-2.0.7.so has inconsistent soname
(libnss_db.so.1)
ldconfig: warning: /lib/libnss_dns-2.0.7.so has inconsistent soname
(libnss_dns.so.1)
ldconfig: warning: /lib/libnss_files-2.0.7.so has inconsistent soname
(libnss_files.so.1)
ldconfig: warning: /lib/libnss_nis-2.0.7.so has inconsistent soname
(libnss_nis.so.1)
ldconfig: warning: /lib/libpthread-0.7.so has inconsistent soname
(libpthread.so.0)
ldconfig: warning: /lib/libresolv-2.0.7.so has inconsistent soname
(libresolv.so.2)
ldconfig: warning: /lib/libutil-2.0.7.so has inconsistent soname
(libutil.so.1)
ld-linux.so.1 =3D> ld-linux.so.1.9.5
ld-linux.so.2 =3D> ld-2.0.7.so
----------------------------------------------------------------
6.
seshu@sita ~>xdpyinfo | grep 'release number'
vendor release number: 3320
7. =
seshu@sita ~>uname -r =
2.0.34
=
any help is greatly appreciated.....
thanks in advance......
-- seshu
[EMAIL PROTECTED] =
____________________________________________________________
satya seshu kumar dammu|4087332589|[EMAIL PROTECTED]
http://www.cslab.uky.edu/~ksdamm0
Dream BIG..... because dreams so small .......
hath no power to move men........
____________________________________________________________________
More than just email--Get your FREE Netscape WebMail account today at htt=
p://home.netscape.com/netcenter/mail