Last active
May 28, 2024 23:20
-
-
Save komamitsu/43a9f3754c32236adc3d824e0624eb48 to your computer and use it in GitHub Desktop.
GraalVM shared library example which receives String arguments called from C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ javac org/komamitsu/foobar/SharedStringMethod.java | |
$ native-image --shared -H:Name=libfoobar | |
$ cc -Wall '-Wl,-rpath,$ORIGIN' -I. -L. -lfoobar main.c | |
$ ./a.out | |
result: hello world |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <libfoobar.h> | |
int main(void) { | |
int ret; | |
graal_isolatethread_t *isolate_thread = NULL; | |
ret = graal_create_isolate(NULL, NULL, &isolate_thread); | |
if (ret != 0) { | |
fprintf(stderr, "graal_create_isolate: %d\n", ret); | |
return 1; | |
} | |
char *result = NULL; | |
result = add(isolate_thread, "hello ", "world"); | |
if (result == NULL) { | |
fprintf(stderr, "add() returned NULL\n"); | |
return 1; | |
} | |
printf("result: %s\n", result); | |
ret = graal_tear_down_isolate(isolate_thread); | |
if (ret != 0) { | |
fprintf(stderr, "graal_tear_down_isolate: %d\n", ret); | |
return 1; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment