import com.sun.jna.Library; import com.sun.jna.Native; public class TestSo { public interface LgetLib extends Library { // 呼叫linux下面的so檔案,注意,這裡只要寫test就可以了,不要寫libtest,也不要加字尾 LgetLib INSTANCE = (LgetLib) Native.loadLibrary("test",LgetLib.class); int add(int a,int b); } public int add(int a,int b){ return LgetLib.INSTANCE.add(a,b); } public static void main(String[] args) { TestSo ts = new TestSo(); int c = ts.add(10,20); System.out.println("10+20="+c); } }
import com.sun.jna.Library; import com.sun.jna.Native; public class TestSo { public interface LgetLib extends Library { // 呼叫linux下面的so檔案,注意,這裡只要寫test就可以了,不要寫libtest,也不要加字尾 LgetLib INSTANCE = (LgetLib) Native.loadLibrary("test",LgetLib.class); int add(int a,int b); } public int add(int a,int b){ return LgetLib.INSTANCE.add(a,b); } public static void main(String[] args) { TestSo ts = new TestSo(); int c = ts.add(10,20); System.out.println("10+20="+c); } }