Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6611681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:00:04+00:00 2026-05-25T20:00:04+00:00

I am trying to create a simple example with JNI. I am having trouble

  • 0

I am trying to create a simple example with JNI. I am having trouble compiling the .cpp source file. I will give all the steps that I have done/tried below. I am trying to follow the tutorial found here: http://java.sun.com/docs/books/jni/html/start.html#27008

I have a Java program called HelloJNI.java

public class HelloJNI
{
    private native void print();

    public static void main(String[] args)
    {   
        new HelloJNI().print();
    }

    static
    {
        System.loadLibrary("HelloJNI");
    }
}

From here I compiled the java file and called

javah -jni HelloJNI to generate HelloJNI.h

From here I create the .cpp source file

#include <jni.h>
#include <iostream>
#include "HelloJNI.h"

using namespace std;

JNIEXPORT void JNICALL
Java_HelloJNI_print(JNIEnv *env, jobject obj)
{
  cout << "Hello JNI!" << endl;
  return;
}

Now that I have all of that I try to create the .dll from the source file, I am using this command to run gcc on cygwin (found this command here – http://www.inonit.com/cygwin/jni/helloWorld/c.html):

gcc -mno-cygwin -I$JAVA_HOME/include -I$JAVA_HOME/include/win32 
    -Wl,--add-stdcall-alias -shared -o HelloJNI.dll HelloJNI.c

When I do this I get an error:

HelloJNI.cpp:1:17: fatal error: jni.h: No such file or directory
compilation terminated.

This is where I am stuck, I don’t really know whey the compiler can’t find jni.h it is in the $JAVA_HOME/include directory.

Results from ls $JAVA_HOME/include:

classfile_constants.h  jdwpTransport.h  jvmti.h      win32
jawt.h                 jni.h            jvmticmlr.h

I know it is a lengthy post, but any help would be awesome.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:00:04+00:00Added an answer on May 25, 2026 at 8:00 pm

    I use the following flags to compile:

    JDK = "c:/Program Files/Java/jdk1.5.0_22/"
    CFLAGS=-Wall -DGCC -DWINDOWS -I$(JDK)/include/win32 -I$(JDK)/include
    

    However, I should mention that I was not able to run my JNI application if the dll was compiled with cygwin gcc. I compiled with the Visual Studio then and it worked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a simple example of an editable gridview, and for some
I am trying to create a simple MongooseJS example program that gets a list
I'm trying to create a simple WebSocket example using the HTML5/JS API. Based on
I am trying to create a simple 3-D app for android that will have
I'm trying to create a simple Automator workflow that will prompt me for where
I'm trying to create a simple example of drawing an image to a layer,
http://jsfiddle.net/nicktheandroid/BcaW3/1/ I'm trying to create a simple canvas version of my jQuery example. When
I'm trying to create a simple youtube player using some javascript. Example is here:
I am trying to create a simple button example, but when I add this
Im trying to create a simple pan and zoom app using silverlight 4, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.