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 6115623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:06:47+00:00 2026-05-23T15:06:47+00:00

I want to call a C subroutine from Java. I’m using JNI. I have

  • 0

I want to call a C subroutine from Java. I’m using JNI. I have created the .java, .c, and .h files, and compiled a DLL. All the files are in the same folder. But when I run the program, it shows an unsatisfiedlinkError. Where am I going wrong…?

As I am learning JNI, the source code I used is the one from: http://www.ibm.com/developerworks/java/tutorials/j-jni/section2.html and things I have already tried:

  • Create a dll using Code::Blocks(ide) and GCC as the compiler
  • Create dll using GCC from command line (Ref. http://sig9.com/node/35 )
  • I am using Win7 32 bit, and I guess all the methods above generate 32-bit DLLs
  • All the solutions I found for creating a DLL (shared library) are for MS VC/VCPP and I don’t have that on my machine right now.

Where is the problem? DLL files are being generated without any exception, but when I run the Java code, it throws the exception.


PS: If there is any theoretical examples that explains how JNI works and what actually it does, then kindly share the link…

The message or exception being thrown:

    c:\myjava1>java Sample1
    Exception in thread "main" java.lang.UnsatisfiedLinkError: Sample1.intMethod(I)I
      at Sample1.intMethod(Native Method)
      at Sample1.main(Sample1.java:11)

At the end of the day after creating dll file lots of times,I am pretty sure that there is possibly no issue with it ,something is wrong with the path …I have changed the loadlibrary method with load method ,but still no luck,…..


as suggested by a MOD:
I have been discussing about this question on the post:JNI error while calling a C subroutine ,I am posting all the codes here as the comments have limited characters… Sample1.c

#include "jni.h"
#include"Sample_Sample1.h"
JNIEXPORT jint JNICALL Java_Sample_Sample1_test(JNIEnv *env, jobject obj){
return(1);
}
void main(){}

Sample1.java

package Sample;

public class Sample1
{
public native int test();
static{ 
System.loadLibrary("Sample1");
}
public static void main(String[] args)
{
 Sample1 sample = new Sample1();
 System.out.println(sample.test());
 }
}

Sample_Sample1.h(generated using javah -jni command)

/* DO NOT EDIT THIS FILE - it is machine generated */
#include "jni.h"
/* Header for class Sample_Sample1 */

#ifndef _Included_Sample_Sample1
#define _Included_Sample_Sample1
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     Sample_Sample1
 * Method:    test
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_Sample_Sample1_test
  (JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

Can anyone guide me where the issue is?In earlier post I mentioned that the code I am using is the one from tutorials ,but to simplyfy the things I have changed the codes …While using **java Sample.Sample1″ i am getting:

c:\myjava1>java Sample.Sample1
Exception in thread “main” java.lang.UnsatisfiedLinkError: Sample.Sample1.test()I
at Sample.Sample1.test(Native Method)
at Sample.Sample1.main(Sample1.java:12)

  • 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-23T15:06:47+00:00Added an answer on May 23, 2026 at 3:06 pm

    You need to have your library explicitly set on your path.

    It may be the case that the flags you are using there aren’t quite right. Try this:

    gcc -Wall -D_JNI_IMPLEMENTATION_ -Wl,--kill-at \
        -I[Java_HOME]/include -I[Java_HOME]/include/win32 \
        -shared -o Sample1.dll Sample1.c
    

    From MinGW GCC site.

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

Sidebar

Related Questions

I want to call a function from a .NET DLL (coded in C#) from
I want to call a c# function from my javascript function. I have a
I am trying to call out to a legacy dll compiled from FORTRAN code.
If all tables I want to delete from have the column gamer_id can i
I want to call my .NET code from unmanaged C++. My process entrypoint is
I want to call some RESTful web services from a J2ME client running on
I want to call an ASHX file and pass some query string variables from
i just want to be able to call a javascritp subroutine on the client,
I want to make a call to a webservice of which I only have
I have 500k unique images in my folder/directory. I want call it by name

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.