It is currently Thu, 25 Feb 2021 06:20:46 GMT

Author Message
 jni using gnu g++ on AIX 4.3.3

I'm trying to call C++ code from a java program (jni) using gnu g++
(2.95.2) compiler (under AIX 4.3). The compilation succeeds but the
native library fails to load when I run the java program (see link line
1).  However, if I extract the .o files from libgcc.a and link directly
with those, the program runs successfully (see link line 2).  Below are
the link commands that I'm running.

1. gcc -shared ./libhello.o -lC -o libhello.a
2. gcc -shared ./libhello.o ./libgcc/*.o -lC -o libhello.a

If I try to build a static library using "gcc -static ./libhello.o  -
lC -o libhello.a" I get the following error:
  ld: 0706-003 Cannot find or read import file: /lib/syscalls.exp
  ld:accessx(): A file or directory in the path name does not exist.
Note: syscalls.exp does not exist anywhere on my file system.  Should
it be part of the GNU gcc/g++ distribution?

Has anyone encountered this problem before?

Also worth noting, the library loads successfully if I don't try to
instantiate an object.  In code below, everything works if I simply
comment out the "foo f;" line.  In running "nm" on the .a file
with "foo f;" and without "foo f;" the only noticeable difference is a
symbol called __builtin_delete.  It seems like at runtime linkage
succeeds with c system libraries but fails with c++ system libraries.
Here's my test code:

#include <jni.h>
#include "HelloWorld.h"
#include <stdio.h>

class foo {
    foo() { printf("foo::foo\n"); }
    ~foo() { printf("foo::~foo\n"); }

Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
    foo f;
    printf("Hello world!\n");

Any thoughts would be greatly appreciated.


Sent via http://www.**-**.com/
Before you buy.

 Fri, 31 Jan 2003 03:00:00 GMT   
 jni using gnu g++ on AIX 4.3.3
        If your system does not have /lib/syscalls.exp, then there is
something severely wrong with your AIX installation.

        The problem with loading shared objects in Java is the result of a
bad "optimization" patch which was included in gcc-2.95 making shared
objects treat the main program as a shared library providing libgcc.a
functions.  The AIX JVM obviously does not provide those functions, so the
load fails.  If you copy the appropriate libgcc.a to another name (like
mylib.a) and add that to the link line, you will receive a number of
duplicate symbol warnings, but the shared object will load and run

        If you use static constructors in the shared object, that will not
work correctly until the next version of GCC is released.

David Edelsohn                                      T.J. Watson Research Center                                  P.O. Box 218
+1 914 945 4364 (TL 862)                            Yorktown Heights, NY 10598

 Wed, 05 Feb 2003 03:00:00 GMT   
   [ 2 post ] 

Similar Threads

1. Using JNI under AIX

2. JNI on AIX using gcc

3. unable to install Gnu g++ on AIX 4.3.3

4. Need help on SIGSEGV error in a g++/JNI application

5. Problem with ibm jdk, jni and g++

6. Multi thread application on AIX using g++ , crash ...

7. problem with template instantiation on AIX using GNU C++ compiler

8. Creating and using a shared library on AIX with GNU

9. Using GNU TAR from NT4 to AIX

10. Where are the JNI headers on AIX?

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software