aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Learning JNI for java,c,cpp combined programming Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Learning JNI for java,c,cpp combined programming" Watch "Learning JNI for java,c,cpp combined programming" New topic

Learning JNI for java,c,cpp combined programming

Mandar Khire
Ranch Hand

Joined: Sep 11, 2007
Posts: 485
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


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

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 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...

Millions saw the apple fall, but Newton asked why.
If you understand, say "understand". If you don't understand, say "don't understand". But if you understand and say "don't understand". How do I understand that you understand? Understand!
Rob Spoor

Joined: Oct 27, 2005
Posts: 19541

You need to add the include paths so gcc / g++ can find the header files:

How To Ask Questions How To Answer Questions
Mandar Khire
Ranch Hand

Joined: Sep 11, 2007
Posts: 485
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 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

Joined: Oct 27, 2005
Posts: 19541

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

Joined: Aug 08, 2012
Posts: 1
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.
I agree. Here's the link:
subject: Learning JNI for java,c,cpp combined programming
Similar Threads
JNI Program RunTime Exceptions
JNI example gives UnsatisfiedLinkError
Eclipse for java & cpp/h files in openjdk
jni.h incorrect
Problem running C++ implementaion in Netbeans 6.8 (cygwin compiler)