Answer the question
In order to leave comments, you need to log in
swig and java. How to make a simple example work?
Initial data:
example.h:
#ifndef _BRIDJ_EXAMPLE_H
#define _BRIDJ_EXAMPLE_H
namespace nl4j {
class SomeClass {
int m_value;
public:
SomeClass(int value);
int someMethod(const char* message);
void someCppFunction(const char* message);
};
}
#endif // _BRIDJ_EXAMPLE_H
%module example
%{
#include "example.h"
%}
%include "example.h"
SomeClass cl = new SomeClass(6);
Exception in thread "main" java.lang.UnsatisfiedLinkError: com.mycompany.testswig.exampleJNI.new_SomeClass(I)J
at com.mycompany.testswig.exampleJNI.new_SomeClass(Native Method)
at com.mycompany.testswig.SomeClass.<init>(SomeClass.java:38)
at com.mycompany.testswig.runme.main(runme.java:18)
%module example
%{
#include "example.h"
%}
int someMethod(const char* message);
void someCppFunction(const char* message);
%include "example.h"
gcc -fPIC -o libexample.so example.cpp example_wrap.cxx -I /usr/lib/jvm/java-8-openjdk-amd64/include/ -I /usr/lib/jvm/java-8-openjdk-amd64/include/linux/ -shared
example_wrap.cxx: In function ‘jint Java_exampleJNI_someMethod(JNIEnv*, jclass, jstring)’:
example_wrap.cxx:252:46: error: ‘someMethod’ was not declared in this scope
result = (int)someMethod((char const *)arg1);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question