Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Learning JNI for java,c,cpp combined programming

 
Mandar Khire
Ranch Hand
Posts: 568
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have
1. JDK 1.7
2. Mingw from webpage.
3. Eclipse Helios for J2EE
4. Eclipse Indigo for J2EE
5. Eclipse Helios for C/C++ programming
6. Boreland compiler
7. Visual Studio so windows compiler also.

I seen How to call C/C++ Program from Java in that jni webpage suggested so i download zip file & try it.
I try to HelloWorld.java

HelloWorld.c

i use command for compile HelloWorld.c

Each time i got error
HelloWorld.c:1:17: fatal error: jni.h: No such file or directory
compilation terminated.

before that i run commands

Both these command successful.

I know as 'Marilyn de Queiroz' written in help-javah

I think that jni is not a beginner topic....

But person who know java, c, cpp can be try out combination of all. Problem is every language have separate IDE/tutorial/examples/books etc

As per HowToAskQuestionsOnJavaRanch
I try to search first about my question... First i try to search in coderanch

1. JNI-without-knowing
2. Getting-cannot-access-Hello-while
3. http://www.coderanch.com/t/425290/java/java/JNI-compiling-file]JNI-compiling-file

In first link 'Paul Clapham' give some way to Java_Native_Access... Thanks for that.

For trying understadn how java & c relate with each other (Basic helloWorld.java which calls HelloWorld.c which further calls h files)
i read & try to study openjdk also.
I try to find out in that process i post few questions in coderanch forum's different section
1. sugestion-understand-openjdk
2. unknown-import
3. Eclipse-java-cpp-files-openjdk

But still lots of confusion & needed proper way to go further...if books/blogs needs to read please suggest...
 
Rob Spoor
Sheriff
Pie
Posts: 20526
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to add the include paths so gcc / g++ can find the header files:
 
Mandar Khire
Ranch Hand
Posts: 568
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob Spoor,
I put path in system properties --> Advanced--> environment Variables--> system Variables-->path-->

same time i put
system properties --> Advanced--> environment Variables--> system Variables-->include-->


I try to run simple java file from cmd & from directory where it put...it also run properly...means jdk also work properly.
I also download code blocks 10.05 for compile & run c files
Today first i try to run basic helloworld.c from cmd... which explain in all c books...
i run command in cmd from directory where i put that c file as g++ helloworld.c
it create a.exe
when i run it console shows "hello world"
But when i build this helloworld.c from code blocks IDE it create helloworld.exe & helloworld.c
means in my pc compiler work perfectly...
now when i try to build jniExample which i download from webpage.
I got error

Now i confuse again...Currently
i can run only java file == yes
i can run only c files == yes
i can run java file which calls c file == no
 
Rob Spoor
Sheriff
Pie
Posts: 20526
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to tell gcc that it needs to create a shared library. If you don't it will look for either a WinMain or main function. I think adding -shared to your compiler flags is enough but I'm not sure.
 
panki jha
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello folks,
I have a similar requirement for my application. I have to call kenen API (third party billing tool written in C) through java application, i have .SO file of kenen. I have created C file for JNI call though java.But i am not able to call kenan API methods those are precompiled in my .SO files.
Please suggest me on calling API methods from my JNI C function.

Any help will be beneficial to me.
Thanks in advance.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic