When I type
java -Djava.library.path="path to opencv lib folder" : "path to my libJavaFileName.so" JavaFileName
I receive the following message:
java: symbol lookup error: "path to my libJavaFileName.so": undefined symbol: _ZN2cv6String8allocateEm
What is the meaning of undefined symbol: _ZN2cv6String8allocateEm and how can I fix it?
I suspect you have a version mismatch between the Java JNI bindings and your version of opencv.
The undefined symbol: _ZN2cv6String8allocateEm arises because your libJavaFileName.so contains a reference to that symbol but the linker cannot find any object file which defines it.
You can use the program c++filt to unmangle the symbol in to a readable name:
> c++filt -n _ZN2cv6String8allocateEm
cv::String::allocate(unsigned long)
If you look in the source of opencv 3.1 you can see that this function does indeed exist (its in stl.cpp in the core module).
The symbol is not defined in the libraries for opencv on my machine (version 2.4.8) but it is defined in libopencv_core.so if I build version 3.1 from source.
Therefore I'm guessing its probably the case that you need to install a newer version of opencv.
Its also worth checking that its actually loading the version of the shared library that you think it is. If you do:
strace -o log.txt java rest_of_your_command_line
Then you can look through log.txt to see which shared libraries are being opened. Try grepping this file for opencv to see if the right version is being loaded.
Your library uses the symbol cv::String::allocate( unsigned long ).
You need to load the proper shared object(s) that provide the symbols that your native code depends on. The best way to do that is to compile your native shared object such that it has dynamic dependencies on those objects by using the proper -L library_name option(s).
Related
I am currently working on an assignment that requires me to utilize the xlsx package in R. I have installed both "xlsx" and "rJava" packages, and have installed the most recent edition of Java to my computer.
However, when I try to load the "xlsx" package, I receive the following error:
enter image description here
> library(xlsx)
Error: package or namespace load failed for ‘xlsx’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(jli, FALSE)
error: unable to load shared object '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jli/libjli.dylib':
dlopen(/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jli/libjli.dylib, 0x000A): tried: '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jli/libjli.dylib' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e)))
Any suggestions of how to fix this so I am able to use the xlsx package?
Thanks.
Tried searching for solutions that suggested I used a different non-Java based package to open the files, read it may be M1 Mac incompatible with Java.
Good day.
What need to do if the script execution leads to a problem java: symbol lookup error /lib64/libnssutil3.so?
I try install Oracle IDM 11gR2 (11.1.2.3) on Oracle Linux 7.5.
Already installed Oracle Databace 12c, OIM RCU, WebLogic, SOA and OAIM.
Now i try Launch WebLogic but script (/idm/oracle/fmw_oim/domains/IDM_domain/bin/startWebLogic.sh) always failed with error:
java: symbol lookup error: /lib64/libnssutil3.so: undefined symbol: PR_GetEnvSecure
Software version:
Java-1.8.0-openjdk-1.8.0.181
nss-3.36.0-5
nss-util-3.36.0-1
I tryed use Java-1.7 and nss-3.28.4 but error was the same.
Can you, please, help me to fix this iisue?
Oh, I was blind. I deleted all versions of java (this is not necessary, but I lost my temper) and reinstall java-1.6.0-openjdk-1.6.0.41. After that Launch WebLogic was successful.
Scripts constantly request to java from the directory /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64/bin/java. Despite the fact that the variable java_home looked like this:
echo $ JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64
I do not know what the reason for this difference is, but as soon as the script started accessing java-1.6.0, the problem disappeared.
I'm following the tutorial at http://docs.aws.amazon.com/kinesis/latest/dev/kinesis-using-sdk-java-add-data-to-stream.html - translating the PutRecords example fom java to scala.
I've included amazon-kinesis-client v1.20 and aws-java-sdk-kinesis v1.9.16 as dependencies.
Compiling using sbt gives me the following error:
value putRecords is not a member of com.amazonaws.services.kinesis.AmazonKinesisClient
Experimenting using the console confirms that this method does not seem to exist on the version of AmazonKinesisClient included with these libraries. Has anyone else had this problem and does anyone know how to resolve it?
The method appears to exist in the aws-java-sdk-kinesis 1.9.16 JAR currently available through Maven:
$ javap -cp aws-java-sdk-kinesis-1.9.16.jar com.amazonaws.services.kinesis.AmazonKinesisClient | grep PutRecords
public com.amazonaws.services.kinesis.model.PutRecordsResult putRecords(com.amazonaws.services.kinesis.model.PutRecordsRequest);
Is it possible that your IDE or classpath contains a reference to another (older) version of the Kinesis or AWS SDKs?
I have a native library for my Android app that uses libjpeg-turbo. I am compiling the library and libjpeg-turbo using NDK. It all seems to be compiling and installing fine (I see all .so files on the phone in /data/data/com.company.app/lib ) and I am calling
System.loadLibrary("jpeg");
System.loadLibrary("zmq");
System.loadLibrary("MySuperLib");
System.loadLibrary("jnilibwrapper");
E/AndroidRuntime(8186): java.lang.UnsatisfiedLinkError: dlopen failed:
could not load library "libMySuperLib.so" needed by "libjnilibrapper.so";
caused by could not load library "libjpeg.so.62" needed by
"libMySuperLib.so"; caused by library "libjpeg.so.62" not found
I found this workaround, making a symlink of the lib like so gets me passed this error
root#klteatt:/data/data/com.company.app/lib # ln -s libjpeg.so libjpeg.so.62
but of course that is not a solution.
Where could we be going wrong? Why is it wanting libjpeg.so.62 specifically?
The issue is caused by MySuperLib being linked with libjpeg-turbo's versioned soname at compile time. Android's JNI runtime does not currently support versioned dynamic libraries, which is why it cannot "find" libjpeg.so, since it only expects an unversioned soname.
One possible way to compile libjpeg-turbo without versioning information is to modify libjpeg-turbo's Makefile.am *LDFLAGS variable, which is passed to libtool. By changing the *LDFLAGS variable to contain libtool's -avoid-version flag, libtool will try to avoid creating libraries with the version information embedded. Creating unversioned shared libraries is usually a terrible idea, but since you can't actually "install" shared libraries on Android at this point, it is fairly safe since your MySuperLib library is the only one that will ever be using the unversioned libjpeg.so.
Here is an example of a patch to libjpeg-turbo's Makefile.am that will produce an unversioned libjpeg.so:
--- Makefile.am 2014-08-28 09:57:37.000000000 -0700
+++ Makefile.am.patched 2014-08-28 09:57:20.000000000 -0700
## -1,5 +1,5 ##
lib_LTLIBRARIES = libjpeg.la
-libjpeg_la_LDFLAGS = -version-info ${LIBTOOL_CURRENT}:${SO_MINOR_VERSION}:${SO_AGE} -no-undefined
+libjpeg_la_LDFLAGS = -avoid-version -no-undefined
include_HEADERS = jerror.h jmorecfg.h jpeglib.h
if WITH_TURBOJPEG
Here is a link to libtool's link-mode manual, for more options and information: http://www.gnu.org/software/libtool/manual/html_node/Link-mode.html
I want to call C++ code from java using JNI. I already followed many tutorials on this, and all are working, when the C++ code is "simple". But the C++ code which I am going to call inludes the opencv library and uses various functions of it. And this is, where I get problems...
What I am doing is the following:
1.) g++ -fPIC -shared -I/usr/lib/jvm/java-1.7.0-openjdk-i386/include -I/usr/lib/jvm/java-1.7.0-openjdk-i386/include/linux -o libHello.so Hello.cpp
which creates the .so file.
2.) I copy my created .so file to the directory where I use it, just as I did with the tutorials, and load it:
static {
System.loadLibrary("Hello");
}
But I get an UnSatisfiedLinkError with undefined symbol: _ZTTN2cv4SURFE
Most probably there is an error in the first step, such that it can not find my opencv library. But I don't know what the correct command would be.
ldd -d libHello.so produces:
linux-gate.so.1 => (0xb777d000)
libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0xb765e000)
libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xb7640000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb7496000)
libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb746a000)
/lib/ld-linux.so.2 (0xb777e000)
undefined symbol: _ZTTN2cv4SURFE (./libHello.so)
undefined symbol: _ZTV11CvStatModel (./libHello.so)
undefined symbol: _ZTVN2cv24BackgroundSubtractorMOG2E (./libHello.so)
undefined symbol: _ZTVN2cv4SURFE (./libHello.so)
undefined symbol: _ZTV5CvSVM (./libHello.so)
edit:
For anyone else getting the same problem:
1.) As some people mentioned, I was not linking against the opencv library.
2.) But this was not enough. I was using this command, as it is also done in some tutorials:
g++ -shared -I/usr/lib/jvm/java-1.7.0-openjdk-i386/include -I/usr/lib/jvm/java-1.7.0-openjdk-i386/include/linux -I/usr/local/include/opencv -L/usr/local/lib -lopencv_nonfree -lopencv_features2d -lopencv_core -lopencv_highgui Hello.cpp -o libHello.so
which caused the undefined symbol error when doing "ldd"
I changed the command to:
g++ Hello.cpp -shared -I/usr/lib/jvm/java-1.7.0-openjdk-i386/include -I/usr/lib/jvm/java-1.7.0-openjdk-i386/include/linux -I/usr/local/include/opencv -L/usr/local/lib -lopencv_nonfree -lopencv_features2d -lopencv_core -lopencv_highgui -o libHello.so
i.e. I just wrote Hello.cpp directly after g++ instead at the end. And this solved the problem.
I don't know why this is working and the previos one didn't. But maybe someone can tell me.
You may need to specify a path to your additional libraries so the JVM can load them. Add an argument to Java:
-Djava.library.path=/path/to/opencv/libs:/other/paths/as/needed
This argument must come before your class name so that Java knows it is an argument for the JVM and not for your program.