我决定尝试编写一个人工神经网络。我计划在Java应用程序中使用它,但该库是用C ++编写的。
考虑到这一点,我决定尝试" razobrotsya JNI"。
有人可以帮我解决问题。
我试图在Java中使用库openANN
,但在编译时,我收到以下错误:
/usr/lib/jvm/java-7-openjdk-amd64/bin/java: symbol lookup error: /home/user/workspace/opneANN_java_test/libfor_java_test.so: undefined symbol: _ZN7OpenANN3NetC1Ev
forJavaNativeAnn.cpp:
#include <OpenANN/OpenANN>
#include <OpenANN/io/Logger.h>
#include <OpenANN/io/DirectStorageDataSet.h>
#include <OpenANN/util/Random.h>
#include <Eigen/Core>
#include <iostream>
#include <eigen3/Eigen/src/Core/Matrix.h>
#include "com_centreit_NativeAnn.h"
JNIEXPORT void JNICALL Java_com_centreit_NativeAnn_run(JNIEnv *env, jclass myclass) {
const int d = 4;
const int f = 4;
const int n = 18;
Eigen::MatrixXd x(n, d);
Eigen::MatrixXd t(n, f);
x <<
2, 0, 0, 0,
2, 0, 0, 1,
2, 0, 1, 1,
2, 0, 1, 2,
2, 1, 0, 2,
2, 1, 0, 1,
1, 0, 0, 0,
1, 0, 0, 1,
1, 0, 1, 1,
1, 0, 1, 2,
1, 1, 0, 2,
1, 1, 0, 1,
0, 0, 0, 0,
0, 0, 0, 1,
0, 0, 1, 1,
0, 0, 1, 2,
0, 1, 0, 2,
0, 1, 0, 1;
t <<
0, 0, 1, 0,
0, 0, 1, 0,
1, 0, 0, 0,
1, 0, 0, 0,
0, 0, 0, 1,
1, 0, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1,
1, 0, 0, 0,
0, 0, 0, 1,
0, 0, 0, 1,
0, 0, 0, 1,
0, 0, 1, 0,
0, 0, 0, 1,
0, 0, 0, 1,
0, 1, 0, 0,
0, 1, 0, 0,
0, 0, 0, 1;
OpenANN::Net net;
OpenANN::makeMLNN(net, OpenANN::LOGISTIC, OpenANN::LOGISTIC, d, f, 1, 1200);
net.trainingSet(x, t);
Eigen::VectorXd v(4);
v << 2, 0, 0, 0;
Eigen::VectorXd out = net(v);
std::cout << out << std::endl;
}
NetBeans IDE中的 make
命令:
g++ -m64 -c -O2 -I/usr/lib/jvm/java-1.7.0-openjdk-amd64/include -std=c++98 -fPIC -MMD -MP -MF "build/Release/GNU-Linux-x86/forJavaNativeAnn.o.d" -o build/Release/GNU-Linux-x86/forJavaNativeAnn.o forJavaNativeAnn.cpp
mkdir -p dist/Release/GNU-Linux-x86
g++ -m64 -o dist/Release/GNU-Linux-x86/libfor_java_test.so build/Release/GNU-Linux-x86/forJavaNativeAnn.o -shared -fPIC
我的Java代码:
public class NativeAnn {
static {
System.loadLibrary("for_java_test");
}
native public static void run();
}