For Newbies using JNI and gcc.

This little command stopped me in my tracks for

about an hour last week and I would like to share it with any one who may need it. When trying to compile a native method in C, Java and gcc here is the command:

gcc -o outfile.so hellowrold.c -shared -fpic-lcrypt -I/usr/java/jdk1.3/include-I/usr/java/jdk1.3/include/linux

where "/usr/java/jdk1.3" is the path to your jdk.

I was just hoping this would help someone.

g'day, --Ian

[481 byte] By [IanMechura] at [2007-9-26 6:39:31]
# 1

Thanks, but one question:

if helloworld.c needs another dynamic library...

how can I do that?

I can compile it with the header file (.h) but when I load my library (System.loadLibrary()), I reach an error:

relocation error, referenced symbol not found.

can you help me, please?

Ddavidjd at 2007-7-1 15:56:41 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

Are you using Linux?

Also after you create your shared Object file you

must move your ".so" file to a directory in your path.

Then run ldconfig and just to make sure, log out of

your account.

Is this even your problem? This is just the basic troubleshooting steps that I would take.

Post more info. if this dose not help.

Good luck,

--Ian

IanMechura at 2007-7-1 15:56:41 > top of Java-index,Java HotSpot Virtual Machine,Specifications...