Link to home
Start Free TrialLog in
Avatar of sudhakar_koundinya
sudhakar_koundinya

asked on

Exact option for compiling C Files for JNI

Hello all,

What exact option i need to give to create a shared library in Linux.

I am able to compile to get shared libray in windows. But failing in linux.

And Don't propose me the links. I have tried almost all . My Problem is I am not a programmer for linux environment. So please help me with the step by step procedure

Thanks
Sudhakar
Avatar of sudhakar_koundinya
sudhakar_koundinya

ASKER

I am getting the follwoing error under linux


 java.lang.UnsatisfiedLinkError: no FileValidator in shared library path
        at java.lang.Runtime.loadLibrary(Runtime.java)
        at java.lang.System.loadLibrary(System.java)
        at FileValidator .<clinit>(FileValidator .java:41)
        at FileValidator .main(FileValidator .java:26)
Avatar of CEHJ
This depends on what compiler(s) is/are installed on your system
I am compiling on Redhat 7.0 linux using gcc compiler
BTW
library path and executable paths are set correctly.

I thing i am missing some thing at compiling options only

Thanks
Sudhakar
Different versions of gcc have different options. Try

man gcc

at the command line for yours
i have already done that

gcc -shared -W1 -o xyz.so xyz.o
to compile use something like:
gcc -c -fPIC xyz.c

you may need to add -I options for any includes that are required
eg. -I/usr/includes

>  java.lang.UnsatisfiedLinkError: no FileValidator in shared library path

Once you have made your lib make sure it is in a directory in LD_LIBRARY_PATH
Despite the fact that you ask for no links, imho you'd be better off looking at the link from where those extracts just posted have been taken as there's further useful info there:

http://quong.best.vwh.net/java/native102.html
what are u talking about???

that link probaly uses the same option cause that's what you use.
I'm sure you can find a miriad of links that use the same options.
CEHJ
 I have alread saw that link

Objects

CEHJ
   I have alread saw that link

Objects
    gcc      -I/home/jdk1.4/include     -I/home/jdk1.4/include/linux FileValidator.c

That is the compiler options I have used. Is that my mistake?



BTW
library path and executable paths are set correctly.

I think i am missing some thing at compiling options only

Thanks
Sudhakar
yes try including -fPIC
please let me try.

Thanks
Sudhakar
Hi sudhakar_koundinya,

Try to specify the extension when you load the library:
    static { System.loadLibrary("FileValidator.so"); }

Otherwise, check the library name, because with linux filenames, uppercase characters are not equals to lowercase characters.

I have failed with  System.loadLibrary but worked with System.load

And Compiler options I have used as suggested by objects
>> I have failed with  System.loadLibrary but worked with System.load
maybe the LD_LIBRARY_PATH variable is not set correctly. If you have many library paths, the separator is ':', and must not include library filenames.

http://www.public.asu.edu/~wjanjua/java/jni/
http://www.netspade.com/articles/java/native.xml
WebStorm,

I did that already. The Library paths are setted correctly but still giving problem :-(

> I have failed with  System.loadLibrary
> but worked with System.load

That suggests the shared lib is ok, but it is not finding it

what are you passing as lib name?
What is your libs filename?
where is your lib located?
What is the value of LD_LIBRARY_PATH?

Hi all again

I understand that library path setting should be correct. And I did the same. But Still it is not working
:-((
what are you passing as lib name?
ReadPST

What is your libs filename?
ReadPST

where is your lib located?
/home/sudhakar/sudha/Outlook/ReadPSTProject

What is the value of LD_LIBRARY_PATH?
???

BTW

Sorry for My late response on this thread. Because I was busy with some other works during these days and neglet this application

Thanks
Sudhakar
>What is your libs filename?
>ReadPST

try renaming it to ReadPST.so

Errrrr............

>>try renaming it to ReadPST.so
I was in hurry to post the message it is ReadPST.so only
> What is the value of LD_LIBRARY_PATH?
> ???

and what is that value exactly?

LD_LIBRARY_PATH=`pwd`
  export LD_LIBRARY_PATH
and what directory do you run that from, ie. what is pwd?
According to example given at java.sun.com

I  give that. pwd is current directory
SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial