在C+中调用函数+;来自Java的共享库 我实现了一个java代码,调用C++共享库名为MaLa.但是,当我尝试调用由库实现的函数时,我得到一个错误:
libmath.so:未定义符号:lt_dlinit 对此有何指导 Java代码:在C+中调用函数+;来自Java的共享库 我实现了一个java代码,调用C++共享库名为MaLa.但是,当我尝试调用由库实现的函数时,我得到一个错误:,java,c++,java-native-interface,wrapper,swig,Java,C++,Java Native Interface,Wrapper,Swig,libmath.so:未定义符号:lt_dlinit 对此有何指导 Java代码: public class runme { static { try { System.loadLibrary("math"); } catch (UnsatisfiedLinkError e) { System.err.println("Native code library failed to load\n" + e); System.exit(1)
public class runme
{
static {
try {
System.loadLibrary("math");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
System.out.println( "Hello and welcome to test_program." );
//assuming that I have NumberVectr filled correctly.
NumbersVectr numbers = new NumberVectr(10);
for (int i=0; i< 10; i++)
{
numbers.add((Number)i);
}
//Now, the problem I am having is in invoking the library
//MathematicsWrapper is a Java wrapper class that wraps the original Mathematics class implemented in C++.
//compute is an arbitrary function implemented in the original C++ class, which itself loads another native library once instantiated.
MathematicsWrapper myMaths = new MathematicsWrapper();
myMaths.compute(numbers);
}
}
Swig定义:
%module math_module
%{
mathematics.h //contains C++ header for MathematicsWrapper class
//so that Java class for MathematicsWrapper can be genereated
%}
%include "std_vector.i"
%template(NumbersVectr) std::vector<int>;
%模块数学\u模块
%{
数学/H//C++包含MaxeWrp类的C++头
//这样就可以生成MathematicsRapper的Java类
%}
%包括“标准向量i”
%模板(NumbersVectr)std::vector;
你也可以分享你的SWIG定义吗?@DoronYakovlev Golani,我刚刚做了。看起来像是谁创建了libmath。所以忘了将它与libltdl链接。添加“load_library(“libltdl.so”);”帮助?你也可以分享你的SWIG定义吗?@DoronYakovlev Golani我刚刚做了。看起来像是谁创建了libmath。所以忘了将它与libltdl链接。添加“load_library(“libltdl.so”);”帮忙?
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 3.0.9
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */
public class MathematicsWrapper {
private transient long swigCPtr;
protected transient boolean swigCMemOwn;
protected MathematicsWrapper(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
protected static long getCPtr(MathematicsWrapper obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
protected void finalize() {
delete();
}
public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
mathsJNI.delete_MathematicsWrapper(swigCPtr);
}
swigCPtr = 0;
}
}
public MathematicsWrapper() {
this(mathsJNI.new_MathematicsWrapper(), true);
}
public int compute() {
return mathsJNI.MathematicsWrapper_compute(swigCPtr, this, NumbersVectr.getCPtr(numbers), numbers);
}
}
%module math_module
%{
mathematics.h //contains C++ header for MathematicsWrapper class
//so that Java class for MathematicsWrapper can be genereated
%}
%include "std_vector.i"
%template(NumbersVectr) std::vector<int>;