integrating native code into java

I am not sure if this is a C question or java.  Anyhow I have been reading the tutorial at

and I have followed it exactly except I had to make a minor change to the cc command as noted below.

Anyhow I compile all the java code and then the C code but when I run it I get the following.

heracles 56% java Main
 4450:/usr/java/bin/../bin/sgi/green_threads/java: rld: Fatal Error: cannot successfully map soname '' under any of the filenames /usr/people/mv135329/java/native/  (
java.lang.UnsatisfiedLinkError: no hello in shared library path
        at java.lang.Runtime.loadLibrary(
        at java.lang.System.loadLibrary(
        at Main.main(

according to the tutorial (step 6) I need set the library path, I did that and that had no effect.  You can see in the error message that that it is looking in the correct directory '' for the library called  This file is in that directory.  So this makes me wonder if I am creating the library wrong?? Here is the command I am using to do it with

'cc -I/usr/java/include -I/usr/java/include HelloWorldImp.c -o -c'

I had to change it a bit from the tutorial.  No matter what I seem to do I always get this message.  I am assuming I am not creating the library properly.  If this is the case this might be a question for the C experts, but I am not sure.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Librarys in UNIX generaly carry a .a  (dot a) extetiion. The -l option assumes that the library will have that extention, so you command should look something like:

cc -I/usr/java/include -I/usr/java/include HelloWorldImp.c -o SomeName -c

You would need to have /usr/java/lib in your path and you would require to be called

The tutorial is not really verry good for native code. I would suggest you look at:

for much better coverage.

Note 1: is not a standard java  lib. Check what your doing carefully, it has to be one of the libs in /usr/java/lib.

Note 2: Save the URL contents of the link I sent you since these  pages appear and disappear without notice.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
micahAuthor Commented:
Followed that tutorial, with even stanger results.  To compile the C code on a sun the tutorial says use the makefile which looks to do the same cc command I was using.  When ever I use the -G I get

ld: ERROR 33: Unresolved data symbol "main" -- 1st referenced by /usr/lib/crt1.o.
ld: INFO 60: Output file removed because of error.

so instead of -G I use -c, that would at least generate the .so file.  For the above tutorial when I do

cc -I/usr/java/include -I/usr/java/include/irix HelloJavaImp.c HelloJava.c -o -c

I get no errors but also no output file or any message.

I am a little confused about your above statement.  Both the tutorials generate a file called  The errors I get seem to be looking for, so what is the '.a'  
The -o compiler flag means that you want the output generated by the compiler to be called

For instance:

cc myprog.c

prduces a.out as output

cc myprog.c -o myprog.exe

produces myprog.exe as output


cc HelloJavaImp.c HelloJava.c -o

will produce an oyput file called

Fact of the matter is, your compile command line is not linking any libraries except for the standar C libs. If you are using jacvah and/or javah -stubs code in your source, you are going to have to link in the java libraries.

The Java libs set up a series of callbacks that allow the Java VM to talk to your app. The code you are generating does not include those callbacks and therfore cannot establish communication at run time.
micahAuthor Commented:
Ok, I found out how to do this elsewhere just had to add a
'-shared' flag to the cc command line and eveything works now.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.