Hello Guys,
I am trying to use JNI, to call an outside function in a C file, which is being called by a Java file. Here is my code:
This is HelloWorld.c
#include "MyOldHello.h"
#include "HelloWorld.h"
JNIEXPORT void JNICALL
Java_HelloWorld_print(JNIEnv *env, jobject obj)
{
helloPrint();
return;
}
This is MyOldHello.c
#include <jni.h>
#include <stdio.h>
#include "MyOldHello.h"
helloPrint()
{
printf("\nHello World!\n");
return;
}
This is MyOldHello.h
void helloPrint();
And this is HelloWorld.h
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class HelloWorld */
#ifndef _Included_HelloWorld
#define _Included_HelloWorld
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: HelloWorld
* Method: print
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_HelloWorld_print
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
and finally my HelloWorld.java
class HelloWorld
{
private native void print();
public static void main(String[] args)
{
new HelloWorld().print();
}
static
{
System.loadLibrary("HelloWorld");
}
}
So basically this is what I type into the Visual Studio Command Prompt:
javac HelloWorld.java
javah -jni HelloWorld
cl -Ic:\Java\jdk1.6.0_20\include -Ic:\Java\jdk1.6.0_20\include\win32 -MD -LD HelloWorld.c -FeHelloWorld.dll
and this is the error I get:
HelloWorld.obj : erroe LNK 2019: unresolved external symbol _helloPrint referenced in function _Java_HelloWorld_print@8
HelloWorld.dll : fatal error LNK1120: 1 unresolved externals
If someone could help me out how to call an external function from a C file which is being called from a Java file using JNI it would greatly help me.
Thanks
Nick
I am trying to use JNI, to call an outside function in a C file, which is being called by a Java file. Here is my code:
This is HelloWorld.c
#include "MyOldHello.h"
#include "HelloWorld.h"
JNIEXPORT void JNICALL
Java_HelloWorld_print(JNIEnv *env, jobject obj)
{
helloPrint();
return;
}
This is MyOldHello.c
#include <jni.h>
#include <stdio.h>
#include "MyOldHello.h"
helloPrint()
{
printf("\nHello World!\n");
return;
}
This is MyOldHello.h
void helloPrint();
And this is HelloWorld.h
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class HelloWorld */
#ifndef _Included_HelloWorld
#define _Included_HelloWorld
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: HelloWorld
* Method: print
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_HelloWorld_print
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
and finally my HelloWorld.java
class HelloWorld
{
private native void print();
public static void main(String[] args)
{
new HelloWorld().print();
}
static
{
System.loadLibrary("HelloWorld");
}
}
So basically this is what I type into the Visual Studio Command Prompt:
javac HelloWorld.java
javah -jni HelloWorld
cl -Ic:\Java\jdk1.6.0_20\include -Ic:\Java\jdk1.6.0_20\include\win32 -MD -LD HelloWorld.c -FeHelloWorld.dll
and this is the error I get:
HelloWorld.obj : erroe LNK 2019: unresolved external symbol _helloPrint referenced in function _Java_HelloWorld_print@8
HelloWorld.dll : fatal error LNK1120: 1 unresolved externals
If someone could help me out how to call an external function from a C file which is being called from a Java file using JNI it would greatly help me.
Thanks
Nick