Hello,
I am getting the following error. Please advide where I may be going wrong.
Exception in thread "main" java.lang.UnsatisfiedLinkError: Plcio.open(Ljava/lang/String;)I at Plcio.open(Native Method) at Plcio.main(Plcio.java:11)
I am certain that the library is present in the path specified.
Plcio.java
public class Plcio {
private native int open(String plcName);
static {
//System.loadLibrary("test");
System.load("/home/usr/plcioExampleslib/libtest.so");
}
public static void main(String[] args) {
Plcio plcio = new Plcio();
int result = plcio.open("virtual");
System.out.println("result = " + result);
}
}
Plc.h
#ifndef _PLC_H
#define _PLC_H
#include<iostream>
#include<string>
#include<vector>
#include<plc.h>
#include<jni.h>
typedef PLC* plcPointer;
class Plc{
public:
Plc() { }
Plc(const std::string &plctype, const std::vector<int> &data):_plctype(plctype),_data(data) {}
JNIEXPORT jint JNICALL Java_Plcio_open (JNIEnv *env, jobject jobj, jstring name) ;
private:
plcPointer _ptr;
const std::string _plctype;
std::vector<int> _data;
};
#endif
Plc.cpp
#include "Plc.h"
#include <jni.h>
using namespace std;
JNIEXPORT jint JNICALL Plc::Java_Plcio_open (JNIEnv *env, jobject jobj, jstring name) {
const char *plcname = (env)->GetStringUTFChars(name, 0);
_ptr = plc_open(const_cast<char*>(plcname));
env->ReleaseStringUTFChars(name, plcname);
if(_ptr == NULL) {
plc_print_error(_ptr, "plc_open\n");
return -1;
} else
cout << " open successfully " << endl;
return 0;
}
Regards,
-H