From owner-freebsd-java Wed Mar 15 11: 3:29 2000 Delivered-To: freebsd-java@freebsd.org Received: from mail.1connect.com (dsl-20919196228.sanjose.ca.internetconnect.net [209.191.96.228]) by hub.freebsd.org (Postfix) with ESMTP id 43E8D37BA78 for ; Wed, 15 Mar 2000 11:03:22 -0800 (PST) (envelope-from keith@1connect.com) Received: from 1connect.com ([10.0.0.75]) by ns1.1connect.com (8.9.3/8.9.1) with ESMTP id MAA66116; Sat, 11 Mar 2000 12:41:17 -0800 (PST) (envelope-from keith@1connect.com) Message-ID: <38CAAFC3.FE74A64D@1connect.com> Date: Sat, 11 Mar 2000 12:42:44 -0800 From: Keith Wong X-Mailer: Mozilla 4.7 [en] (Win95; I) X-Accept-Language: en MIME-Version: 1.0 To: Andrew Sudell , Nate Williams Cc: freebsd-java Subject: JNI and Shared Library Content-Type: multipart/mixed; boundary="------------7B1A422692F97A9F78A42183" Sender: owner-freebsd-java@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org 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