Last active
October 10, 2018 17:52
-
-
Save samtkaplan/35a1ce57145143b6e34f77ced8096611 to your computer and use it in GitHub Desktop.
Julia/JNI Bug
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
package org.foo.bug.jni; | |
public class Bug { | |
static { | |
System.loadLibrary("Bug"); | |
} | |
public native static void unreachable(); | |
} |
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
package org.foo.bug.jni; | |
import org.foo.bug.jni.Bug; | |
public class Demo { | |
public static void main(String[] args) { | |
Bug.unreachable(); | |
} | |
} |
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
# julia config | |
JL_SHARE = $(shell julia -e 'print(joinpath(Sys.BINDIR, Base.DATAROOTDIR, "julia"))') | |
CFlAGS += $(shell $(JL_SHARE)/julia-config.jl --cflags) | |
CXXFLAGS += $(shell $(JL_SHARE)/julia-config.jl --cflags) | |
LDFLAGS += $(shell $(JL_SHARE)/julia-config.jl --ldflags) | |
LDLIBS += $(shell $(JL_SHARE)/julia-config.jl --ldlibs) | |
# JNI config | |
CXXFLAGS += -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux | |
all: libBug.so bug.jar | |
bug.jar: org/foo/bug/jni/Bug.java | |
javac org/foo/bug/jni/Bug.java | |
jar cf bug.jar org/foo/bug/jni/Bug.class | |
libBug.so : org_foo_bug_jni_Bug.o | |
gcc $(CFLAGS) $(CXXFLAGS) -shared -o libBug.so org_foo_bug_jni_Bug.o $(LDFLAGS) $(LDLIBS) | |
org_foo_bug_jni_Bug.o : org_foo_bug_jni_Bug.c org_foo_bug_jni_Bug.h | |
gcc -fPIC $(CFLAGS) $(CXXFLAGS) -c org_foo_bug_jni_Bug.c | |
clean : | |
rm -f *.so *.o *.jar org/foo/bug/jni/Bug.class | |
install : | |
mkdir -p ../deps/usr/include | |
mkdir -p ../deps/usr/lib | |
mkdir -p ../deps/usr/share/java | |
cp org_foo_bug_jni_Bug.h ../deps/usr/include | |
cp libBug.so ../deps/usr/lib | |
cp bug.jar ../deps/usr/share/java |
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 "org_foo_bug_jni_Bug.h" | |
#include "julia.h" | |
JNIEXPORT void JNICALL | |
Java_org_foo_bug_jni_Bug_unreachable( | |
JNIEnv *env, | |
jclass class) | |
{ | |
printf("line %d in %s\n", __LINE__, __FILE__); | |
jl_init(); | |
printf("line %d in %s\n", __LINE__, __FILE__); | |
jl_eval_string("using Pkg"); | |
printf("line %d in %s\n", __LINE__, __FILE__); | |
jl_atexit_hook(0); | |
printf("line %d in %s\n", __LINE__, __FILE__); | |
} |
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
/* DO NOT EDIT THIS FILE - it is machine generated */ | |
#include <jni.h> | |
/* Header for class org_foo_bug_jni_Bug */ | |
#ifndef _Included_org_foo_bug_jni_Bug | |
#define _Included_org_foo_bug_jni_Bug | |
#ifdef __cplusplus | |
extern "C" { | |
#endif | |
/* | |
* Class: org_foo_bug_jni_Bug | |
* Method: unreachable | |
* Signature: ()V | |
*/ | |
JNIEXPORT void JNICALL Java_org_foo_bug_jni_Bug_unreachable | |
(JNIEnv *, jclass); | |
#ifdef __cplusplus | |
} | |
#endif | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment