daily pastebin goal
14%
SHARE
TWEET

Untitled

a guest Jul 23rd, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Compile the C++ code creating a shared library (or shared object in UNIX)
  2.  
  3. $ clang++ TestJNI.cpp -o libTestJNI.so -fPIC -shared -std=c++11 -I$HOME/opt/java/include -I$HOME/opt/java/include/linux
  4.  
  5. Run the application
  6.  
  7. $ scala -save load.scala
  8. dir = /home/archbox/opengl/jni/libTestJNI.so
  9. Hello world java
  10. i = 0
  11. i = 1
  12. i = 2
  13. i = 3
  14. i = 4
  15. Library version        = version 3.4
  16. vector3DLen(3, 4, 5)   = 7.0710678118654755
  17. Average of 1, 2 ... 8  = 4.5
  18.  
  19. $ scala -save load.jar
  20. dir = /home/archbox/opengl/jni/libTestJNI.so
  21. Hello world java
  22. i = 0
  23. i = 1
  24. i = 2
  25. i = 3
  26. i = 4
  27. Library version        = version 3.4
  28. vector3DLen(3, 4, 5)   = 7.071
  29.  
  30. Check compilation output
  31.  
  32. $ file libTestJNI.so
  33. libTestJNI.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=6a21fdf13b652757f1773db2069095eaa050b759, not stripped
  34.  
  35. Check symbols
  36.  
  37. $ nm -D libTestJNI.so | grep " T "
  38. 0000000000000f08 T _fini
  39. 0000000000000a28 T _init
  40. 0000000000000d40 T Java_TestJNI_average
  41. 0000000000000cc0 T Java_TestJNI_getVersion
  42. 0000000000000c20 T Java_TestJNI_printDisplay
  43. 0000000000000cf0 T Java_TestJNI_vector3DLen
  44. 0000000000000e00 T main
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top