• Post Reply Bookmark Topic Watch Topic
  • New Topic

jni in linux

 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

is it possible to have the jni functions in linux...
we want to call c++ functions in java....

Thanks in advance...
 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we want to have an interface for the c++ coding in java, so we are thinking of jni.
we are familiar with jni in windows.. we create dll files ans use them.. but what about dll in linux..
 
Joe Ess
Bartender
Posts: 9361
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A "shared library" provides the same functionality in the Unix world as a DLL does in Windows. The Advanced Programming for Java book has an example with instructions for both Windows and Linux.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DLLs are a Windows concept; Unix/Linux uses *.so libraries. Maybe this will get you started: http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jniexamp.html
 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you Joe and ulf
 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

Thank you very much for your help. i'm able to create a .so file in linux. but when running the program it is returning unsatisfied linker error



can any one tell what that means.
like we place the .dll file in system32 folder in windows, do we need to place the .so file in any folder in linux.
any other suggestions may help me.. please

i'm trying the example in the following link
http://www.ibm.com/developerworks/systems/library/es-jniexamples.html
.

thanks in advance
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Native libraries need to be in a directory that's listed in the PATH environment variable. Something like "echo $PATH" should tell you which ones those are.
 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you Ulf.
i need to search some other topic on how to set the environmental variables in linux.
 
Rob Spoor
Sheriff
Posts: 20817
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read this. Although it handles CLASSPATH, you can apply the same for all environment variables you want.
 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you rob
 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm getting the following error...
do not know what it could be.



anyone help please.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're not by any chance using "nativelib" in the loadLibrary call, are you? You need to use the name of your library.
 
Rob Spoor
Sheriff
Posts: 20817
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're using "nativelib" in the loadLibrary call, the native library file should be called libnativelib.so

For libraries loaded by loadLibrary, the file should have ".dll" appended in Windows, and be wrapped in "lib" and ".so" in Unix. For instance, nativelib.dll / libnativelib.so, helloworld.dll / libhelloworld.so, etc
 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you ulf and rob....

i resolved the above issue for the sample program in linux....
i just placed the created .so file in /usr/lib and the program ran with out any hitch..
but the problem is that when using our project file to create the .so file i'm getting loads of errors....

some of the errors are..



i do not know what are these errors... i'm new to linux..
if possible can you just give me some suggestions on this error list..


 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and some more info if you should need it..

we are using third party stack which has some header files.. we do not know to interface them with jni..

at present we are testing only one method(function) to check the working functionality.

thanks in advance
 
Rob Spoor
Sheriff
Posts: 20817
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you set the include path correctly when compiling the C code?
 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes rob,

i did set the include path correctly..
the problem is with the header files.. it is not recognizing them.
what to do.... any solution for this


thanks in advance
 
Rob Spoor
Sheriff
Posts: 20817
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The headers should be recognized just fine if your include path is correct.

Can you tell me the following:
- how did you include those, using <pj/activesock.h> or using "pj/activesock.h"?
- where are those files located?

If you use <pj/activesock.h> (and the others as well), these need to be in the include path - the pj folder, not the separate files.
If you use "pj/activesock.h" (and the others as well), these need to be relative to your current path.
 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi rob,

i'm inlcuding the header files in < > except for the jni.h and the the java file header which are in " "
and as suggested i placed the folders containg the header files in the /usr/java/jdk1.6.0_13/include path and still i get the same errors..

i ever changed the entire header files to " " and placed the header files foldewr in the curent directory and still the same errors...
any suggestions will help

thanks in advance
 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any suggestions please
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!