< prev index next >

doc/panama_foreign.md

Print this page
rev 55895 : 8223033: panama_foreign.md should have a basic hello world example
Reviewed-by: TBA

@@ -21,10 +21,73 @@
 
 It is generally a good idea to give jextract a bunch of extra memory since a lot of big system headers are transitively included. The extra memory will make the jextract run significantly faster. Windows support was added only recently, and the memory usage of jextract has not been optimized yet, so this is a workaround. You can give extra memory by passing e.g. `-J-Xmx8G` to jextract as an additional argument, which in this example gives jextract 8 gigabytes of memory.
 
 Commands are tested in PowerShell.
 
+## Hello World
+
+### Hello World C Header
+
+```C
+
+#ifndef helloworld_h
+#define helloworld_h
+
+extern void helloworld(void);
+
+```
+
+### Hello World C Source
+
+```C
+
+#include <stdio.h>
+
+#include "helloworld.h"
+
+void helloworld(void) {
+    printf("Hello World!\n");
+}
+
+```
+
+### jextract a Jar file for helloworld.h
+
+```sh
+
+jextract -t org.hello -L . -lhelloworld --record-library-path helloworld.h -o helloworld.jar
+
+```
+
+### Java program that uses extracted helloworld interface
+
+```java
+
+import org.hello.helloworld_lib;
+
+import static org.hello.helloworld_lib.*;
+
+public class HelloWorld {
+    public static void main(String[] args) {
+        try (Scope s = helloworld_lib.scope().fork()) {
+            helloworld();
+        }
+    }
+}
+
+```
+
+### Running the Java code that invokes helloworld
+
+```sh
+
+javac -cp helloworld.jar HelloWorld.java
+
+java -cp helloworld.jar:. HelloWorld
+
+```
+
 ## Embedding Python interpreter in your Java program (Mac OS)
 
 ### jextract a Jar file for Python.h
 
 ```sh
< prev index next >