knowledge-database (beta)

Current group: comp.programming

making shared library with gcc

making shared library with gcc  
nipspu
 Re: making shared library with gcc  
Andreas Klimas
 Re: making shared library with gcc  
Jens.Toerring at physik.fu-berlin.de
From:nipspu
Subject:making shared library with gcc
Date:Wed, 19 Jan 2005 15:19:37 +0200
hello

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

#include
#include "HelloWorld.h";
#include

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?
From:Andreas Klimas
Subject:Re: making shared library with gcc
Date:Wed, 19 Jan 2005 16:06:54 +0100
nipspu wrote:
> hello
>
> im trying to make a shared library from HelloWorld.c. the code is here.
>
> #include
> #include "HelloWorld.h";
> #include
>
> 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?


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

best wishes
Andreas Klimas
From:Jens.Toerring at physik.fu-berlin.de
Subject:Re: making shared library with gcc
Date:19 Jan 2005 15:20:04 GMT
Andreas Klimas wrote:
> nipspu wrote:
>> im trying to make a shared library from HelloWorld.c. the code is here.
>>
>> #include
>> #include "HelloWorld.h";
>> #include
>>
>> 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?

$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.

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

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
   

Copyright © 2006 knowledge-database   -   All rights reserved