javaCPP命令
#源代码转class类
javac src/main/java/com/xl/javacpp/*.java -classpath lib/javacpp-1.5.7.jar -d target/classes -encoding utf-8
#class类转C++动态库,根据需求去掉某些参数
java -jar lib/javacpp-1.5.7.jar -classpath target/classes -nocpp -nocompile -nodelete -o foo -Xcompiler -L. -Dplatform.includepath=$(pwd)/include/ -encoding utf-8 -jarprefix jnidemo com.xl.javacpp.NativeLibrary
传递ByteBuffer
ByteBuffer buffer=ByteBuffer.allocateDirect(8);
buffer.put((byte)3);
buffer.put((byte)4);
buffer.put((byte)6);
buffer.put((byte)7);
buffer.putInt(10000000);
//切换到读模式
buffer.flip();
Processor.putEnv();
Processor.process(buffer,8);
public static native void process(java.nio.Buffer buffer, int size);
static inline void process(void *buffer, int size) {
std::cout << "Processing in C++..." << size << std::endl;
char *databuf=(char*)buffer;
for(int i=0;i<size;i++)
{
printf("%d\n",*databuf);
databuf++;
}
}
传递JNIENV对象
static void putEnv(void *jni,void *jc)
{
}
public static native @Raw(withEnv=true) void putEnv();
网友评论