求jna调用so可以返回struct的实例。不甚感激!我的老是报jvm crash,请高手指点!
我的老是报jvm crash,请高手指点!
1、mymd5.c
#include "mymd5.h"
//struct stmymd5 getMyMd5(struct starg srg)
struct stmymd5 getMyMd5()
{
struct stmymd5 st;
st.retcode = 88;
st.mymd5 = "hello yyyyyy";
return st;
}
2、mymd5.h
#include <stdio.h>
#include <stdlib.h>
struct stmymd5
{
int retcode;
};
struct stmymd5 getMyMd5();
3、TestSo.java
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Structure;
public class TestSo{
public interface LgetLib extends Library {
LgetLib INSTANCE = (LgetLib) Native.loadLibrary("mystruct", LgetLib.class);
public MyMd5Struct getMyMd5();
}
public static class MyMd5Struct extends Structure
{
public int retcode;
public static class ByValue extends MyMd5Struct implements Structure.ByValue { }
public static class ByReference extends MyMd5Struct implements Structure.ByReference { }
}
public MyMd5Struct getMyMd5(){
return LgetLib.INSTANCE.getMyMd5();
}
public static void main(String[] args) {
MyMd5Struct myMd5Struct = LgetLib.INSTANCE.getMyMd5();
System.out.println("get retcode = " + myMd5Struct.retcode);
}
}
------解决方案--------------------报错如下:
#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# SIGSEGV (0xb) at pc=0x6df764b1, pid=27654, tid=3086923456
#
# Java VM: Java HotSpot(TM) Server VM (1.5.0_16-b02 mixed mode)
# Problematic frame:
# C [jna58332.tmp+0xe4b1] ffi_call+0x75
#
# An error report file with more information is saved as hs_err_pid27654.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#
Aborted
------解决方案--------------------围观帮顶
------解决方案-------------------- An error report file with more information is saved as hs_err_pid27654.log
lz看看这个日志文件
------解决方案--------------------看不懂啊,怎么看啊,指点一下呗:
#
# An unexpected error has been detected by HotSpot Virtual Machine: