G
GfxGuy
I've been getting the dreaded and oft discussed
"java.lang.UnsatisfiedLinkError" exception...
---------
The Java:
---------
public class MyJNI
{
static
{
System.loadLibrary("MyJNI");
}
public native boolean chown(String filename, int user);
}
--------
The C++:
--------
#include "MyJNI.h"
#include <sys/types.h>
#include <unistd.h>
JNIEXPORT jboolean JNICALL Java_MyJNI_chown (JNIEnv *env, jobject jobj,
jstring fname, jint fowner)
{
jboolean rval = JNI_FALSE;
jboolean iscopy;
const char *name;
int owner = fowner;
name = env->GetStringUTFChars(fname, &iscopy);
if(chown(name,owner,owner) == 0) rval = JNI_TRUE;
env->ReleaseStringChars(fname, (jchar *) name);
return rval;
}
-----------
The problem
-----------
The System.loadlibrary function works just fine - libMyJNI.so is indeed
there and in the ld_library_path (I know this because I had to work
through all of that, too). It says it can't find "chown", the specific
function:
java.lang.UnsatisfiedLinkError: chown
at com.turner.utilities.MyJNI.chown(Native Method)
at com.turner.utilities.MyUtils.chown(Unknown Source)
..
..
..
MyUtils.chown is just another wrapper on top so that other higher level
classes don't have to care about the JNI aspect of it.
I haven't programmed in C/C++ in a long time... mostly written in Java
and other scripting languages for the past few years, I just needed a
way to "chown" files. My HelloWorld test worked just fine with the
same compiler and linker options:
INC= -I${JAVA_HOME}/include \
-I${JAVA_HOME}/include/linux
gcc -c ${INC} -fPIC -g MyJNI.c++
gcc -shared -W1 -lstdc++ -o libMyJNI.so MyJNI.o
TIA for any advice on either this specific problem, or if you could
point me to something that exists to perform chown, that'd be cool...
"java.lang.UnsatisfiedLinkError" exception...
---------
The Java:
---------
public class MyJNI
{
static
{
System.loadLibrary("MyJNI");
}
public native boolean chown(String filename, int user);
}
--------
The C++:
--------
#include "MyJNI.h"
#include <sys/types.h>
#include <unistd.h>
JNIEXPORT jboolean JNICALL Java_MyJNI_chown (JNIEnv *env, jobject jobj,
jstring fname, jint fowner)
{
jboolean rval = JNI_FALSE;
jboolean iscopy;
const char *name;
int owner = fowner;
name = env->GetStringUTFChars(fname, &iscopy);
if(chown(name,owner,owner) == 0) rval = JNI_TRUE;
env->ReleaseStringChars(fname, (jchar *) name);
return rval;
}
-----------
The problem
-----------
The System.loadlibrary function works just fine - libMyJNI.so is indeed
there and in the ld_library_path (I know this because I had to work
through all of that, too). It says it can't find "chown", the specific
function:
java.lang.UnsatisfiedLinkError: chown
at com.turner.utilities.MyJNI.chown(Native Method)
at com.turner.utilities.MyUtils.chown(Unknown Source)
..
..
..
MyUtils.chown is just another wrapper on top so that other higher level
classes don't have to care about the JNI aspect of it.
I haven't programmed in C/C++ in a long time... mostly written in Java
and other scripting languages for the past few years, I just needed a
way to "chown" files. My HelloWorld test worked just fine with the
same compiler and linker options:
INC= -I${JAVA_HOME}/include \
-I${JAVA_HOME}/include/linux
gcc -c ${INC} -fPIC -g MyJNI.c++
gcc -shared -W1 -lstdc++ -o libMyJNI.so MyJNI.o
TIA for any advice on either this specific problem, or if you could
point me to something that exists to perform chown, that'd be cool...