Tech Support > Computers & Technology > Programming > making shared library with gcc
making shared library with gcc
Posted by nipspu on January 19th, 2005


hello

im trying to make a shared library from HelloWorld.c. the code is here.

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

JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
{
printf("Hello world!\n");
return;
}


it goings to be used with java. how do i should run gcc? and do i have to
put jni.h available to $PATH?

Posted by Andreas Klimas on January 19th, 2005


nipspu wrote:

gcc -shared HelloWorld.o -o HelloWorld.so
^^^^^^^

best wishes
Andreas Klimas


Posted by Jens.Toerring@physik.fu-berlin.de on January 19th, 2005


Andreas Klimas <klimas@klimas-consulting.com> wrote:
$PATH won't help you there. If 'jni.h' isn't in one of the directories
the compiler looks into per default you would need the compiler option
'-I', directly followed (i.e without spaces in between) by the path to
where 'jni.h' is, e.g.

-I/us/local/include/java

if 'jni.h' is in that directory.

You typically also need '-fpic' (or -fPIC' on some architectures for
libraries with lots of exported symbols) both when compiling and
linking, so make that

gcc -shared -fpic HelloWorld.c -o HelloWorld.so

(Exception are machines that always produce position-independent code,
which is what 'pic' stands for.)
Regards, Jens
--
\ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de
\__________________________ http://www.toerring.de