2

Someone sent me his static library(lib.a) and a header file(lib.h) it should be written in C++, I've used gcc compiler to convert the static library(lib.a) into a shared library(.so). Now I want to use Java to call library to use it's functions.

I have tried System.load and System.loadLibrary but I don't know how to call it's functions. For example, I've see there is a function call MoveFront(int) from the header file and it will return the integer for the status.

extern int MoveFront(int);

There's a way to do that? Thank you.

I am using Ubuntu 13.10, JDK 1.8.0_20, gcc 4.6.3.

Confucius
  • 419
  • 3
  • 7
  • 14

1 Answers1

2

You can not call them directly in Java

You have to build a bridge using JNI

link your lib.a with bridge.c into libbridge.so then, java can use System.loadLibrary("bridge") to use it

some guide here https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html

farmer1992
  • 7,816
  • 3
  • 30
  • 26