#ifndef _ADDER_H #define _ADDER_H __declspec(dllexport) int add(int, int); #endif
#include "adder.h" __declspec(dllexport) int add(int a, int b) { return a + b; }
// импорт jextract'нутых "заголовочных" классов import static com.example.adder_h.*; public class Example { public static void main(String[] args) { System.out.println(add(3, 5)); } }
cl /LD adder.c
jextract
utility to generate a java interface based on the header file: jextract -L . -l adder -o adder.jar -t "com.example" adder.h
javac -cp adder.jar Example.java java -cp .;adder.jar Example
import java.foreign.Libraries; import java.foreign.Scope; import java.foreign.memory.Pointer; import static org.python.Python_h.*; import static org.python.pylifecycle_h.*; import static org.python.pythonrun_h.*; public class PythonMain { public static void main(String[] args) { Py_Initialize(); try (Scope s = Scope.newNativeScope()) { PyRun_SimpleStringFlags(s.allocateCString( "print(sum([33, 55, 66]))\n"), Pointer.nullPointer()); } Py_Finalize(); } }
jextract -L "C:\Python37" -l python37 -o python.jar -t "org.python" --record-library-path C:\Python37\include\Python.h
javac -cp python.jar PythonMain.java java -cp .;python.jar PythonMain
Source: https://habr.com/ru/post/440470/