Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 11 Mar 2000 12:42:44 -0800
From:      Keith Wong <keith@1connect.com>
To:        Andrew Sudell <asudell@acm.org>, Nate Williams <nate@mt.sri.com>
Cc:        freebsd-java <freebsd-java@freebsd.org>
Subject:   JNI and Shared Library
Message-ID:  <38CAAFC3.FE74A64D@1connect.com>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------7B1A422692F97A9F78A42183
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi Folks,
I have project that we are intended to use JNI to wrap the C native
Code, so I can call java instead of the C. But, we have problem after we

try to link the imdsi.o to libimdsi.so (Freebsd gcc environment).  Then
we are not even run this InsideLine.class. I have compared solaris's cc
compiler and gcc compiler, i see some difference on the linker option,
but i know i am get wrong on the linker shared library is it I pick the
right one.

Those are the some reference of how to compile the shared library.
Here is the example of how to compile the shared library in Solaris and
Win32:
http://web2.java.sun.com/docs/books/tutorial/native1.1/stepbystep/step5.html

In Solaris the way to get shared library:
cc -G -I/usr/local/java/include -I/usr/local/java/include/solaris \
HelloWorldImp.c -o libhello.so
Here is the defination -G in Solaris's cc compiler:
-G in Solaris is:
Passes the option to the link editor to produce a shared object rather
than a dynamically linked executable. This option is passed to ld(1),
and cannot be used with the -dn option.
http://docs.sun.com/ab2/coll.33.5/CUG/@Ab2PageView/2194?Ab2Lang=C&Ab2Enc=iso-8859-1

Here is the gcc in the freebsd's linker's option:
http://gcc.gnu.org/onlinedocs/gcc_2.html#SEC13

------------------------------------------------------------------------------------------------------

Those are how we link the shared library in gcc
% gcc -shared -I/usr/local/jdk1.1.8/include
-I/usr/local/jdk1.1.8/include/freebsd
-I/usr/home/eproj/codebase/com/ingram
-I/usr/home/eproj/codebase/com/ingram/hw_appl.h -I/usr/include/rpc/rpc.h
-I/usr/home/eproj/codebase/com/ingram/com_ingram_InsideLine.h
InsideLine.c -fPIC -o libimdsi.so

InsideLine.c: In function `Java_InsideLine_Call_1Server':
InsideLine.c:52: warning: cast to pointer from integer of different size

InsideLine.c: In function `Java_InsideLine_Close_1Client':
InsideLine.c:74: warning: cast to pointer from integer of different size

InsideLine.c: In function `Java_InsideLine_Open_1Client':
InsideLine.c:87: warning: cast from pointer to integer of different size

Then, i try to run the test program.
% java com.ingram.InsideLine
java.lang.UnsatisfiedLinkError: Open_Client
        at com.ingram.InsideLine.main(InsideLine.java:23)

% file libimdsi.so
libimdsi.so: ELF 32-bit LSB shared object, Intel 80386, version 1
(FreeBSD), not stripped

>From the output about, i think the libimdsi.so have not linked with the

Call_Server function.  Do you have any ideal how to make that imdsi.o's
three functions linked into the libimdsi.so.  I had made full path for
java in FreeBSD enirovnment
setenv  LD_LIBRARY_PATH
.:/usr/home/eproj/codebase/com/ingram:/usr/home/eproj/codebase
setenv  CLASSPATH
/usr/local/mm.mysql.jdbc-2.0pre3:/usr/local/share/java/classes/jsdk.jar:/usr/home/eproj/codebase

Other, i have the Helloworld.java and .c (from sun website). i can
compile it and run with no problem,
yes, i know the the Helloworld.c is wrote by us.  is that a problem that
becuase i import the .object instead of .c file,
do we have any way to link the .object file?? Is that i am using the gcc
-shared in the correct way?


Thanks a million!

Keith.




--------------7B1A422692F97A9F78A42183
Content-Type: application/x-sh;
 name="InsideLine.sh"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="InsideLine.sh"

gcc -shared -I/usr/local/jdk1.1.8/include -I/usr/local/jdk1.1.8/include/freebsd -I/usr/home/eproj/codebase/com/ingram -I/usr/home/eproj/codebase/com/ingram/hw_appl.h -I/usr/include/rpc/rpc.h -I/usr/home/eproj/codebase/com/ingram/com_ingram_InsideLine.h -I/usr/home/eproj/codebase/com/ingram/imdsi.o InsideLine.c -fPIC -o libimdsi.so

--------------7B1A422692F97A9F78A42183
Content-Type: text/x-vcard; charset=us-ascii;
 name="keith.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Keith Wong
Content-Disposition: attachment;
 filename="keith.vcf"

begin:vcard 
n:Wong;Keith
tel;pager:415-791-4007
tel;fax:408-363-1803
tel;work:408-363-1800
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
email;internet:keith@dominocomp.com
fn:Keith Wong
end:vcard

--------------7B1A422692F97A9F78A42183--



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-java" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?38CAAFC3.FE74A64D>