I am getting something like the following:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no viewerNativeDLL in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1734)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at viewer.SarBufferedImage.<clinit>(SarBufferedImage.java:356)
at viewer.viewerJPanel.<init>(viewerJPanel.java:34)
at viewer.ViewerView.initComponents(ViewerView.java:457)
at viewer.ViewerView.<init>(ViewerView.java:33)
at viewer.ViewerApp.main(ViewerApp.java:21)
This is even though I have set LD_LIBRARY_PATH to the path where I built my shared object.
Did I build that shared object wrong? This is the makefile I used to build the shared lib:
CPP = g++
CFLAGS = -O3 -Wall -fopenmp -fPIC
INC = -I ../../VC/readers/ -I../../VC/writers -I../../VC/common/ -I /home/dcole/software/xerces-c-3.1.1/src -I /home/dcole/software/java/jdk1.6.0_23/include -I /home/dcole/software/java/jdk1.6.0_23/include/linux
LIB2 = -L/usr/lib64/ -L../../lib/IDT.a -L../../lib/Linux/libxerces-c.a -L../../lib/Linux/libxerces-c-3.1.so -lcurl -lidn -ldl -lssl -L../../lib/Linux/libfftw3f.a -lpthread
all: ViewerNative.o
${CPP} ${CFLAGS} -shared -o libviewerNativeDLL.so ViewerNative.o ${LIB2}
ViewerNative.o: ViewerNative.cpp viewer_SarBufferedImage.h
${CPP} ${INC} ${CFLAGS} -c ViewerNative.cpp ${LIB2}
Am I missing something with the way I am creating viewerNativeDLL.so?
If I do a ldd-d libviewerNativeDLL.so I get this:
undefined symbol: _ZTIN11xercesc_3_117SAXParseExceptionE (./libviewerNativeDLL.so)
undefined symbol: _ZN11xercesc_3_117SAXParseExceptionD1Ev (./libviewerNativeDLL.so)
linux-vdso.so.1 => (0x00007fff41f21000)
libcurl.so.4 => /usr/lib64/libcurl.so.4 (0x00007fc30bcd4000)
libidn.so.11 => /lib64/libidn.so.11 (0x00007fc30baa2000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fc30b89d000)
libssl.so.8 => /usr/lib64/libssl.so.8 (0x00007fc30b649000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fc30b42d000)
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007fc30b122000)
libm.so.6 => /lib64/libm.so.6 (0x00007fc30ae9f000)
libgomp.so.1 => /usr/lib64/libgomp.so.1 (0x00007fc30ac92000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fc30aa77000)
libc.so.6 => /lib64/libc.so.6 (0x00007fc30a709000)
libldap-2.4.so.2 => /usr/lib64/libldap-2.4.so.2 (0x00007fc30a4c4000)
librt.so.1 => /lib64/librt.so.1 (0x00007fc30a2bb000)
libgssapi_krb5.so.2 => /usr/lib64/libgssapi_krb5.so.2 (0x00007fc30a090000)
libkrb5.so.3 => /usr/lib64/libkrb5.so.3 (0x00007fc309df4000)
libk5crypto.so.3 => /usr/lib64/libk5crypto.so.3 (0x00007fc309bcd000)
libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007fc3099ca000)
libz.so.1 => /lib64/libz.so.1 (0x00007fc3097b5000)
libssl3.so => /lib64/libssl3.so (0x00007fc309581000)
libsmime3.so => /lib64/libsmime3.so (0x00007fc309357000)
libnss3.so => /lib64/libnss3.so (0x00007fc309024000)
libnssutil3.so => /lib64/libnssutil3.so (0x00007fc308e05000)
libplds4.so => /lib64/libplds4.so (0x00007fc308c02000)
libplc4.so => /lib64/libplc4.so (0x00007fc3089fe000)
libnspr4.so => /lib64/libnspr4.so (0x00007fc3087c1000)
libssh2.so.1 => /usr/lib64/libssh2.so.1 (0x00007fc30859a000)
/lib64/ld-linux-x86-64.so.2 (0x0000003e34a00000)
libcrypto.so.8 => /usr/lib64/libcrypto.so.8 (0x00007fc308215000)
liblber-2.4.so.2 => /usr/lib64/liblber-2.4.so.2 (0x00007fc308005000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x00007fc307dec000)
libsasl2.so.2 => /usr/lib64/libsasl2.so.2 (0x00007fc307bd1000)
libkrb5support.so.0 => /usr/lib64/libkrb5support.so.0 (0x00007fc3079c8000)
libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007fc3077c6000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007fc30758e000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fc307370000)
libfreebl3.so => /lib64/libfreebl3.so (0x00007fc307113000)
So I can clearly see they are missing, but how come I dont get any errors? What is the fix? I have linked in the static and shared libraries from xerces
edit: I am now actually getting this when I try to run it:
$ java -Djava.library.path=/home/dcole/IM/work/ext/VC.viewer/viewerNativeDLL/ -jar viewer.jar
Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/dcole/IM/work/ext/VC.viewer/viewerNativeDLL/libviewerNativeDLL.so: /home/dcole/IM/work/ext/VC.viewer/viewerNativeDLL/libviewerNativeDLL.so: undefined symbol: _ZTIN11xercesc_3_117SAXParseExceptionE
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1803)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1728)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at viewer.SarBufferedImage.<clinit>(SarBufferedImage.java:356)
at viewer.viewerJPanel.<init>(viewerJPanel.java:34)
at viewer.ViewerView.initComponents(ViewerView.java:457)
at viewer.ViewerView.<init>(ViewerView.java:33)
at viewer.ViewerApp.main(ViewerApp.java:21)
edit2:
following the suggestion below, I changed the say I was linking to the libraries, which gives me this command and output:
g++ -O3 -Wall -fopenmp -fPIC -shared -o libviewerNativeDLL.so ViewerNative.o -L/usr/lib64/ ../../lib/IDT.a ../../lib/Linux/libxerces-c.a ../../lib/Linux/libxerces-c-3.1.so -lcurl -lidn -ldl -lssl ../../lib/Linux/libfftw3f.a -lpthread
/usr/bin/ld: ../../lib/Linux/libxerces-c.a(PlatformUtils.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
../../lib/Linux/libxerces-c.a: could not read symbols: Bad value
I guess I will have to recompile xerces with fPIC?
I think the reason is the way you link to the libraries:
-L../../lib/Linux/libxerces-c-3.1.so
-L option is used to specify the search directories for the libraries, and the libraries themselves are specified using -l option.
It should probably be:
-L../../lib/Linux/ -lxerces-c-3.1
or just put the lib without -L
../../lib/Linux/libxerces-c-3.1.so
edit:
You may check with nm libxerces-c-3.1.so|grep ParseException (same for libxerces-c.a) if there's such symbol defined. Make sure also that libxerces that you use for compilation (include paths -I) and the one you use for linking is the same.
Passing -Wl,-no-undefined when linking your library will help you see undefined symbols during linking rather than trying to load the library later.
You are linking again shared libraries, e.g. -L../../lib/Linux/libxerces-c-3.1.so Unless all these are included, your shared library which needs them cannot load.
Related
I am trying to include a C++ library with my swing project..
When I compile the jnilib/so, with stdio.h it works fine for this:
gcc -shared -o libhello.jnilib hello.c -fPIC -I/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/include/darwin
I am trying to import and need to use gnu-libstdc++/4.9
How do I link my java project?
When I try to build the jni file:
It will throw this:
test.c:5:10: fatal error: 'string' file not found
#include <string>
EDIT
Now when I link to this:
-I /Users/tnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64/include
It throws this error:
...
/Users/tnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64/include/bits/ctype_base.h:69:37: error: use of undeclared identifier '_U'
static const mask graph = _P | _U | _L | _N;
^
/Users/tnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64/include/bits/ctype_base.h:69:42: error: use of undeclared identifier '_L'
static const mask graph = _P | _U | _L | _N;
^
/Users/tnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64/include/bits/ctype_base.h:69:47: error: use of undeclared identifier '_N'
static const mask graph = _P | _U | _L | _N;
^
/Users/tnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64/include/bits/ctype_base.h:70:32: error: use of undeclared identifier '_C'
static const mask cntrl = _C;
^
/Users/tnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64/include/bits/ctype_base.h:71:32: error: use of undeclared identifier '_P'
static const mask punct = _P;
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
EDIT2
After adding -I /Users/timnuwin/Documents/ndk/android-ndk-r12b/platforms/android-17/arch-x86/usr/include now it throws:
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cwchar:164:11: error: no member named 'vfwscanf' in the global namespace
using ::vfwscanf;
~~^
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cwchar:170:11: error: no member named 'vswscanf' in the global namespace
using ::vswscanf;
~~^
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cwchar:174:11: error: no member named 'vwscanf' in the global namespace
using ::vwscanf;
~~^
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cwchar:191:11: error: no member named 'wcstof' in the global namespace
using ::wcstof;
~~^
In file included from hello.cpp:6:
In file included from /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/sstream:38:
In file included from /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/istream:38:
In file included from /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/ios:44:
In file included from /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/basic_ios.h:37:
In file included from /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/locale_facets.h:39:
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cwctype:89:11: error: no member named 'iswblank' in the global namespace; did you
mean 'isblank'?
using ::iswblank;
~~^
/Users/timnuwin/Documents/ndk/android-ndk-r12b/platforms/android-17/arch-x86/usr/include/ctype.h:88:5: note: 'isblank' declared here
int isblank(int);
^
1 warning and 5 errors generated.
EDIT3
Okay I think I'm a little closer here's the updated includes...
gcc -shared -o libhello.jnilib hello.cpp -fPIC
-I/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/include
-I/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/include/darwin
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/backward
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/bits
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/debug
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/decimal
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/experimental
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/ext
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/parallel
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/profile
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/tr1
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/tr2
But now it throws:
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/tr1/stdio.h:8:10: fatal error: 'tr1/cstdio' file not found
#include
EDIT
Alrighty, setting the include to be the base dir include -I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include now throws:
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cstdio:98:11: error: no member named 'FILE' in the global namespace
using ::FILE;
~~^
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cstdio:99:11: error: no member named 'fpos_t' in the global namespace
using ::fpos_t;
~~^
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cstdio:101:11: error: no member named 'clearerr' in the global namespace
using ::clearerr;
~~^
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cstdio:102:11: error: no member named 'fclose' in the global namespace
using ::fclose;
~~^
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cstdio:103:11: error: no member named 'feof' in the global namespace
using ::feof;
~~^
clang++ -shared -o libhello.jnilib hello.cpp -fPIC -funwind-tables -no-canonical-prefixes -fexceptions -frtti -Os -g -DNDEBUG -DNDEBUG -fPIC -std=gnu++11 -I/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/include/darwin -isystem /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86/include -isystem /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -I /Users/timnuwin/Documents/ndk/android-ndk-r12b/platforms/android-17/arch-x86/usr/include
That cmd was able to create my jnilib file. :D 3 days later hehe
I'm trying add a Java installation on my Yocto build. I would like to run on my embedded system a Java application I developed but I can't correctly install Java.
When I try to run java I get the following:
./java: No such file or directory
I googled for a solution and found that I need to install libc6 32 bit version.
I proceeded to modify my local.conf file as following:
MACHINE ??= "intel-corei7-64"
require conf/multilib.conf
MULTILIBS = "multilib:lib32"
DEFAULTTUNE_virtclass-multilib-lib32 = "x86"
DISTRO ?= "poky"
PACKAGE_CLASSES ?= "package_rpm"
SDKMACHINE ?= "x86_64"
EXTRA_IMAGE_FEATURES ?= "debug-tweaks"
USER_CLASSES ?= "buildstats image-mklibs image-prelink"
PATCHRESOLVE = "noop"
BB_DISKMON_DIRS = "\
STOPTASKS,${TMPDIR},1G,100K \
STOPTASKS,${DL_DIR},1G,100K \
STOPTASKS,${SSTATE_DIR},1G,100K \
STOPTASKS,/tmp,100M,100K \
ABORT,${TMPDIR},100M,1K \
ABORT,${DL_DIR},100M,1K \
ABORT,${SSTATE_DIR},100M,1K \
ABORT,/tmp,10M,1K"
PACKAGECONFIG_append_pn-qemu-native = " sdl"
PACKAGECONFIG_append_pn-nativesdk-qemu = " sdl"
CONF_VERSION = "1"
CORE_IMAGE_EXTRA_INSTALL = " lib32-glibc"
CORE_IMAGE_EXTRA_INSTALL += "opencv opencv-samples libopencv-core-dev libopencv-highgui-dev libopencv-imgproc-dev libopencv-objdetect-dev libopencv-ml-dev"
But i get this error:
Build Configuration:
BB_VERSION = "1.32.0"
BUILD_SYS = "x86_64-linux"
NATIVELSBSTRING = "universal-4.8"
TARGET_SYS = "x86_64-poky-linux"
MACHINE = "intel-corei7-64"
DISTRO = "poky"
DISTRO_VERSION = "2.2.1"
TUNE_FEATURES = "m64 corei7"
TARGET_FPU = ""
meta
meta-poky
meta-yocto-bsp = "morty:924e576b8930fd2268d85f0b151e5f68a3c2afce"
meta-intel = "morty:6add41510412ca196efb3e4f949d403a8b6f35d7"
meta-oe = "morty:fe5c83312de11e80b85680ef237f8acb04b4b26e"
meta-intel-realsense = "morty:2c0dfe9690d2871214fba9c1c32980a5eb89a421"
Initialising tasks: 100% |#####################################################################################################################################################################################################| Time: 0:00:22
NOTE: Executing SetScene Tasks
NOTE: Executing RunQueue Tasks
ERROR: rmc-1.0-r0 do_package: QA Issue: rmc: Files/directories were installed but not shipped in any package:
/usr/lib
/usr/lib/librmclefi.a
/usr/lib/librsmpefi.a
Please set FILES such that these items are packaged. Alternatively if they are unneeded, avoid installing them or delete them within do_install.
rmc: 3 installed and not shipped files. [installed-vs-shipped]
ERROR: rmc-1.0-r0 do_package: Fatal QA errors found, failing task.
ERROR: rmc-1.0-r0 do_package: Function failed: do_package
ERROR: Logfile of failure stored in: /home/dalben/WorkingBuild/poky/filec/tmp/work/corei7-64-poky-linux/rmc/1.0-r0/temp/log.do_package.16424
ERROR: Task (/home/dalben/WorkingBuild/poky/meta-intel/common/recipes-bsp/rmc/rmc.bb:do_package) failed with exit code '1'
NOTE: Tasks Summary: Attempted 2954 tasks of which 2937 didn't need to be rerun and 1 failed.
Summary: 1 task failed:
/home/dalben/WorkingBuild/poky/meta-intel/common/recipes-bsp/rmc/rmc.bb:do_package
Summary: There were 3 ERROR messages shown, returning a non-zero exit code.
Any help is appreciated.
EDIT: Updated question here.
For your information, you will need to do a lot of work in putting Java into your image.
Your current image does not have any java related programs installed since I do not see meta-java in your compile process.
CORE_IMAGE_EXTRA_INSTALL is restricted to OE Core images; So if you have your own image recipe, the variable will does not work unless you inherit core-image.bbclass
Here is an example on putting "openjdk-7-jre" to the image: http://wiki.hioproject.org/index.php?title=OpenHAB:_WeMo_Switch
The key elements are: meta-java, meta-oracle-java .
You will need to add them to your conf/bblayers.conf
BBLAYERS = " \
${BSPDIR}/sources/meta-java \
${BSPDIR}/sources/meta-oracle-java \
"
In conf/local.conf, add this line to install openjdk-7-jre.
IMAGE_INSTALL_append = " openjdk-7-jre "
To add more on what you need, check on https://layers.openembedded.org/layerindex/branch/master/layers/
I'm trying to test BeanShell's command line interpreter in how it processes basic Java commands and syntax on my machine, and see if I can customise its behavior in any way. I've installed version 2.0b4 on my machine running OS X 10.10.1 (the JAR file is in /Library/Java/Extensions as per the instructions).
It's the closest thing to what I've been looking for, an interactive Java interpreter, but it doesn't have some standard features which a good interpreter should have.
I'd like to be able to use the Up arrow key to reuse a previous command, but at the moment it doesn't recognise it, it just shows a control sequence. Is there a way to customise this for BeanShell?
Is there a way to get BeanShell to print out the value of a variable if I've created it beforehand, just by naming it, like
String s = new String( "Hello World!" );
s;
Hello World!.
This is possible in Python for example.
According to the documentation on importing Java classes which(<java class>); should return the classpath location of the specified Java class. But which( java.lang.String ); does not work for me, I get a NullPointerException:
bsh % which(java.lang.String);
Start ClassPath Mapping
Mapping: Directory /Users/srm
// Error: // Uncaught Exception: Method Invocation cp.getClassSource : at Line: 42 : in file: /bsh/commands/which.bsh : cp .getClassSource ( className )
Called from method: which : at Line: 8 : in file: : which ( java .lang .String )
Target exception: java.lang.NullPointerException
java.lang.NullPointerException
Any pointers or help would be appreciated.
Run beanshell with jline.
Download jline jar from http://jline.sourceforge.net/index.html and then you can do:
java -cp jline-1.0.jar:bsh-2.0b4.jar jline.ConsoleRunner bsh.Interpreter
Line editing capability will be provided by jline. I found this hint here.
There are issues running with jline2. First, you'll get:
$ java -cp jline-2.12.jar:bsh-2.0b4.jar jline.ConsoleRunner bsh.Interpreter
Exception in thread "main" java.lang.NoClassDefFoundError: jline/ConsoleRunner
Due to this issue which is fixed. But then, use the new class and you still get:
$ java -cp jline-2.12.jar:bsh-2.0b4.jar jline.console.internal.ConsoleRunner bsh.Interpreter
Exception in thread "main" java.lang.IllegalArgumentException: wrong number of arguments
due to this issue which is not fixed yet.
Use show() command which will trigger showing of value.
bsh % show();
bsh % String s = new String("Hello World");
bsh % s;
<Hello World>
bsh %
It is mentioned in the Useful BeanShell Commands section of the documentation.
Doesn't work for me either
It doesn't fail in my case, but it didn't find it either.
bsh % which(java.lang.String);
Start ClassPath Mapping
Mapping: Archive: file:/Users/me/beanshell/jline-1.0.jar
Mapping: Archive: file:/Users/me/beanshell/bsh-2.0b4.jar
Mapping: Archive: file:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
End ClassPath Mapping
null
bsh %
I'd like to use Clojure code within Java. The Clojure code itself should implement a Java-interface (TestGenClassInterface).
My project.clj is:
(defproject com.stackoverflow.clojure/tests "0.1.0-SNAPSHOT"
:description "Tests of Clojure test-framework."
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]
[instaparse "1.3.4"]]
:source-paths ["src/main/clojure"]
:java-source-paths ["src/main/java"]
:test-paths ["src/test/clojure"]
:java-test-paths ["src/test/java"]
;:aot :all
)
The Java interface looks like this:
package com.stackoverflow.clojure;
public interface TestGenClassInterface {
public String addToString(String text, String appendText);
}
The Clojure code is:
(ns com.stackoverflow.clojure.testGenClass
(:gen-class
:name com.stackoverflow.clojure.TestGenClass
:implements com.stackoverflow.clojure.TestGenClassInterface
:prefix "java-"))
(def ^:private pre "START: ")
(defn java-addToString [this text post]
(str pre text post))
(java-addToString "TexT" " :END")
I expected, that after running lein compile or "Run as Clojure-Application" in eclipse+CounterClockwise a .class file (named TestGenClass.class) is generated an saved within *compile-path* (here: target/classes/com/stackoverflow/clojure/). Unfortunately it's not.
When adding :aot :all to my project.clj, I get the following stacktrace:
Compiling com.stackoverflow.clojure.testGenClass
Exception in thread "main" java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol, compiling:(com/stackoverflow/clojure/testGenClass.clj:1:1)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6651)
at clojure.lang.Compiler.analyze(Compiler.java:6445)
at clojure.lang.Compiler.analyze(Compiler.java:6406)
at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:5782)
at clojure.lang.Compiler$TryExpr$Parser.parse(Compiler.java:2191)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6644)
at clojure.lang.Compiler.analyze(Compiler.java:6445)
at clojure.lang.Compiler.analyze(Compiler.java:6406)
at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:5782)
at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5217)
at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3846)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6642)
at clojure.lang.Compiler.analyze(Compiler.java:6445)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6632)
at clojure.lang.Compiler.analyze(Compiler.java:6445)
at clojure.lang.Compiler.analyze(Compiler.java:6406)
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3665)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6646)
at clojure.lang.Compiler.analyze(Compiler.java:6445)
at clojure.lang.Compiler.analyze(Compiler.java:6406)
at clojure.lang.Compiler.compile1(Compiler.java:7221)
at clojure.lang.Compiler.compile1(Compiler.java:7216)
at clojure.lang.Compiler.compile(Compiler.java:7292)
at clojure.lang.RT.compile(RT.java:398)
at clojure.lang.RT.load(RT.java:438)
at clojure.lang.RT.load(RT.java:411)
at clojure.core$load$fn__5066.invoke(core.clj:5641)
at clojure.core$load.doInvoke(core.clj:5640)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5446)
at clojure.core$compile$fn__5071.invoke(core.clj:5652)
at clojure.core$compile.invoke(core.clj:5651)
at user$eval9.invoke(form-init4595004281107083893.clj:1)
at clojure.lang.Compiler.eval(Compiler.java:6703)
at clojure.lang.Compiler.eval(Compiler.java:6693)
at clojure.lang.Compiler.load(Compiler.java:7130)
at clojure.lang.Compiler.loadFile(Compiler.java:7086)
at clojure.main$load_script.invoke(main.clj:274)
at clojure.main$init_opt.invoke(main.clj:279)
at clojure.main$initialize.invoke(main.clj:307)
at clojure.main$null_opt.invoke(main.clj:342)
at clojure.main$main.doInvoke(main.clj:420)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:383)
at clojure.lang.AFn.applyToHelper(AFn.java:156)
at clojure.lang.Var.applyTo(Var.java:700)
at clojure.main.main(main.java:37)
Caused by: java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol
at clojure.lang.RT.seqFrom(RT.java:505)
at clojure.lang.RT.seq(RT.java:486)
at clojure.core$seq.invoke(core.clj:133)
at clojure.core$map$fn__4245.invoke(core.clj:2551)
at clojure.lang.LazySeq.sval(LazySeq.java:40)
at clojure.lang.LazySeq.seq(LazySeq.java:49)
at clojure.lang.RT.seq(RT.java:484)
at clojure.core$seq.invoke(core.clj:133)
at clojure.core$map$fn__4245.invoke(core.clj:2551)
at clojure.lang.LazySeq.sval(LazySeq.java:40)
at clojure.lang.LazySeq.seq(LazySeq.java:49)
at clojure.lang.Cons.next(Cons.java:39)
at clojure.lang.RT.boundedLength(RT.java:1654)
at clojure.lang.RestFn.applyTo(RestFn.java:130)
at clojure.core$apply.invoke(core.clj:624)
at clojure.core$mapcat.doInvoke(core.clj:2586)
at clojure.lang.RestFn.invoke(RestFn.java:423)
at clojure.core$generate_class.invoke(genclass.clj:164)
at clojure.core$gen_class.doInvoke(genclass.clj:638)
at clojure.lang.RestFn.invoke(RestFn.java:1557)
at clojure.lang.Var.invoke(Var.java:519)
at clojure.lang.AFn.applyToHelper(AFn.java:270)
at clojure.lang.Var.applyTo(Var.java:700)
at clojure.lang.Compiler.macroexpand1(Compiler.java:6552)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6630)
... 46 more
Compilation failed: Subprocess failed
The proximate issue you have is a missing :aot :all in your project.clj file. Without that the ahead-of-time compilation will not be attempted.
Once you put that in, you'll have the following further issues:
you must prefix the names of the functions designated to become Java methods (default prefix is -);
you must include this as an explicit first argument of each such method (this is the recommended convention, but any name is acceptable);
you must correct your :implements clause: it takes a vector as the value, even if it has a single member.
According to http://clojure.org/compilation
... the implementation functions for instance methods will always take an
additional first arg corresponding to the object the method is called
upon, called by convention 'this' here.
Try adding 'this' to each function definition.
(defn java-addToString [this text post]
...
http://clojure.org/compilation mentions the compilation process makes use of
... *compile-path*, which must be in the classpath
The default location is a classes folder.
The second answer to Stack Overflow question Compiling Clojure? mentions that this path is relative to the jvm startup folder. If you did lein repl from the main project folder (the folder where project.clj lives) then creating a classes folder there should make it work.
i'm compiling a jni project.here is detail of the problem i encountering:
r
oot#kaiwiiho:/home/kaiwii/svn# make
gcc -shared build/utimebufClass.o build/contextClass.o build/fsClass.o build/javafuse_jni.o build/statClass.o build/statvfsClass.o build/fileinfoClass.o build/conninfoClass.o -o build/libjavafuse.so
gcc -g -Wall `pkg-config --cflags fuse` -Iinclude -I/usr/java/jdk1.6.0_31/include -I/usr/java/jdk1.6.0_31/include/linux `pkg-config --libs fuse` -L/usr/java/packages/lib/i386 -L/lib -L/usr/lib -ljvm -Lbuild -ljavafuse src/javafuse.c -o javafuse
src/javafuse.c: In function ‘javafuse_readdir’:
src/javafuse.c:2194:22: warning: cast from pointer to integer of different size
src/javafuse.c:2195:25: warning: cast from pointer to integer of different size
src/javafuse.c:2207:15: warning: cast to pointer from integer of different size
src/javafuse.c:2208:18: warning: cast to pointer from integer of different size
src/javafuse.c:2256:16: warning: cast from pointer to integer of different size
src/javafuse.c:2257:19: warning: cast from pointer to integer of different size
src/javafuse.c:2271:15: warning: cast to pointer from integer of different size
src/javafuse.c:2272:18: warning: cast to pointer from integer of different size
src/javafuse.c: In function ‘javafuse_releasedir’:
src/javafuse.c:2332:12: warning: assignment from incompatible pointer type
src/javafuse.c: In function ‘javafuse_fsyncdir’:
src/javafuse.c:2420:12: warning: assignment from incompatible pointer type
/usr/bin/ld: cannot find -ljvm
collect2: ld returned 1 exit status
make: *** [javafuse] 错误 1
root#kaiwiiho:/home/kaiwii/svn# ldconfig
root#kaiwiiho:/home/kaiwii/svn# gedit /etc/ld.so.conf
root#kaiwiiho:/home/kaiwii/svn# make
gcc -shared build/utimebufClass.o build/contextClass.o build/fsClass.o build/javafuse_jni.o build/statClass.o build/statvfsClass.o build/fileinfoClass.o build/conninfoClass.o -o build/libjavafuse.so
gcc -g -Wall `pkg-config --cflags fuse` -Iinclude -I/usr/java/jdk1.6.0_31/include -I/usr/java/jdk1.6.0_31/include/linux `pkg-config --libs fuse` -L/usr/java/packages/lib/i386 -L/lib -L/usr/lib -ljvm -Lbuild -ljavafuse src/javafuse.c -o javafuse
src/javafuse.c: In function ‘javafuse_readdir’:
src/javafuse.c:2194:22: warning: cast from pointer to integer of different size
src/javafuse.c:2195:25: warning: cast from pointer to integer of different size
src/javafuse.c:2207:15: warning: cast to pointer from integer of different size
src/javafuse.c:2208:18: warning: cast to pointer from integer of different size
src/javafuse.c:2256:16: warning: cast from pointer to integer of different size
src/javafuse.c:2257:19: warning: cast from pointer to integer of different size
src/javafuse.c:2271:15: warning: cast to pointer from integer of different size
src/javafuse.c:2272:18: warning: cast to pointer from integer of different size
src/javafuse.c: In function ‘javafuse_releasedir’:
src/javafuse.c:2332:12: warning: assignment from incompatible pointer type
src/javafuse.c: In function ‘javafuse_fsyncdir’:
src/javafuse.c:2420:12: warning: assignment from incompatible pointer type
/usr/bin/ld: cannot find -ljvm
collect2: ld returned 1 exit status
make: *** [javafuse] 错误 1
And for sake that the the libjvm.so have aready exisited in the /usr/lib,i directly make a conf file,/etc/ld.so.conf.d/my.conf:
/usr/lib
/usr/local/lib
and then i use command ldconfig.
but unfortunately,i still encounter the same problem yet.
Any idea?thx
This command:
gcc -g -Wall `pkg-config --cflags fuse` -Iinclude \
-I/usr/java/jdk1.6.0_31/include \
-I/usr/java/jdk1.6.0_31/include/linux `pkg-config --libs fuse` \
-L/usr/java/packages/lib/i386 -L/lib -L/usr/lib -ljvm -Lbuild -ljavafuse \
src/javafuse.c -o javafuse
is incorrect. The order of libraries and sources on the link line matters, and your order is wrong.
But that's not what your problem is right now. You insist that libjvm.so exists in /usr/lib, but have shown no evidence that it does. What does ls -l /usr/lib/libjvm.so actually print?
Note that it would be highly unusual to find libjvm.so in /usr/lib. Usually one would expect to find it in e.g. /usr/java/packages/lib/i386/server, and you are not searching that directory.
Update:
well. libjvm.so is not actually in the /usr/lib but in /usr/java/jdk1.6.0_31/jre/lib/i386/server
In that case, you need to add -L/usr/java/jdk1.6.0_31/jre/lib/i386/server to your link line.
And i gedit a conf file ...
Obviously that's not sufficient.
The error is coming because JAVA_HOME & LD_LIBRARY_PATH is not consistent for Linux.So after analysis i discover that JAVA_HOME and LD_LIBRARY_PATH is resetting everytime whenever the terminal window is closed.
So setting the JAVA_HOME permanently resolved the error like:-
JAVA_HOME=/usr/java/latest
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/java/latest/bin:/bin:/sbin:/usr/lib64/qt-3.3/bin
LD_LIBRARY_PATH=/usr/java/jdk1.8.0_111/jre/lib/amd64/server:/usr/local/lib:/usr/lib64:/usr/lib:/usr/local/lib64: