As some of you have read, Ive been working with JNI for these days. Ive found that JNA may be easier to manage and also allows some other things.
I have this very simple program:
The .cpp:
#include <stdio.h>
#include "PruebasDeJNA.h"
int suma(int a,int b)
{
return a+b;
}
The .h:
#include <stdio.h>
int suma(int,int);
All it does is add two numbers and return them. Nothing more.
In my .java program:
package hola;
import com.sun.jna.*;
public class Mundo
{
public interface PruebasDeJNA extends Library
{
PruebasDeJNA INSTANCE = (PruebasDeJNA)Native.loadLibrary((Platform.isWindows() ? "PruebasDeJNA" : "c"),PruebasDeJNA.class);
int suma(int a,int b);
}
public static void main(String[] args)
{
System.out.println(PruebasDeJNA.INSTANCE.suma(5, 7));
}
}
The error that it gives me is that it cannot find the function "suma" in the library.
As you can see, avoiding porting the code from C++ to Java is neccesary as there are too many lines to port over and the program is alot of math so one miscalulation could throw away alot of work.
Thanks for the help