com.googlecode.javacv not working

TristanTheHakSoar
TristanTheHakSoar used Ask the Experts™
on
Hey all,

I have been trying desperately to get javacv working on my MacBook 10.6.8 64-bit without any luck.

I followed the following quickstart guide: http://code.google.com/p/javacv/

I want to use eclipse to do this, but unfortunately i get the following error:
Exception in thread "main" java.lang.UnsatisfiedLinkError:
/private/var/folders/LB/LB61BZtPFq4LULxHfE3xPE+++TI/-Tmp-/libjniopencv_core6616875771379943551.dylib:  
Library not loaded: lib/libopencv_core.2.4.dylib  
Referenced from: /private/var/folders/LB/LB61BZtPFq4LULxHfE3xPE+++TI/-Tmp-/libjniopencv_core6616875771379943551.dylib  
Reason: image not found

I have tried dumping libopencv_core.2.4.dylib into every lib folder on my system with no luck and have tried changing the following variable in configurations.
DYLD_FALLBACK_LIBRARY_PATH
which i have set to:
/usr/local/lib
and
opt/local/lib
and various other lib directories i have placed the .dylib file into.

I have moved onto compiling on the command line providing the classpath to the jar files via the -cp option and the class compiles, but when i try to run i get the error:

Exception in thread "main" java.lang.NoClassDefFoundError: MotionDetector

So i pulled all the code out of motion detector except for a single print statement that would tell me the classpath "System.out.println(System.getProperty("java.classpath"))" and i still get the error which leads me to believe that the imports are causing the problem.

import com.googlecode.javacpp.Loader;
import com.googlecode.javacv.*;
import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import static com.googlecode.javacv.cpp.opencv_calib3d.*;
import static com.googlecode.javacv.cpp.opencv_objdetect.*;

I compile and run with commands like:
javac -cp ../javacv.jar:../javacpp.jar MotionDetector.java
java -cp ../javacv.jar:../javacpp.jar MotionDetector

I have searched the internet for days now trying to find the correct way to include the googlecode into my classpath or on my system but haven't found any, i did follow a tutorial that installed the google plugin into eclipse so i figure it should be there, any help would be hugely appreciated.

- Tristan
MotionDetector2.java
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

Commented:

Author

Commented:
In eclipse and on the command line the java.library.path returned is:

:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java

the first contains the files librxtxSerial.jnilib and RXTXcomm.jar

the second has a number of other jar and jnilib files

the last contains libjdns_sd.jnilib

neither of these are the path to the javacv jar files i included as external jars in the project if that helps.
Top Expert 2016

Commented:
neither of these are the path to the javacv jar files i included as external jars in the project if that helps.


The important thing is that the native libraries must be in one of those directories. The classpath is another issue, and of course your jars must be in that
How to Generate Services Revenue the Easiest Way

This Tuesday! Learn key insights about modern cyber protection services & gain practical strategies to skyrocket business:

- What it takes to build a cloud service portfolio
- How to determine which services will help your unique business grow
- Various use-cases and examples

Author

Commented:
he classpath is another issue, and of course your jars must be in that

I have noticed that on printing "java.classpath" it returns null, might this be the problem? I had assumed that my settings in the eclipse run/debug configuration merged the locations of those jar files with the classpath but perhaps I am mistaken, i will dig around a little more on those settings and try to get back with a success unless you come back with a better idea.

Also i decided that it would be a good idea to check the bitness of everything and all my librairies as well as eclipse are 64 so no problem there it seems.

I've also checked to make sure that I have the google app engine properly installed and it seems to be a part of my project, any way I can detect this or the jar files in my eclipse classpath? There are no errors that eclipse picks up and I am able to use all of the objects in the libraries, it is just the compilation that fails returning null pointers for whatever objects i try to create.
Top Expert 2016

Commented:
I have noticed that on printing "java.classpath" it returns null, might this be the problem?

No. That property doesn't exist. It's

System.out.println(System.getProperty("java.class.path"));

Open in new window

Author

Commented:
ah kk, so i tried that and got the path this time with all the necessary jars included, i don't see a link to the opencv_core.2.4.dylib file though it probably shouldn't be in here?

I have gone into /opt/local/lib/ and found the following files:

libopencv_core.2.4.0.dylib
libopencv_core.2.4.dylib -> libopencv_core.2.4.0.dylib
libopencv_core.dylib -> libopencv_core.2.4.dylib

i did the opencv through macports so i assume these links should be working correctly, perhaps i should try to uninstall and reinstall the port?

Author

Commented:
well that didnt work either, perhaps the way to go would be to implement in c++ and use a java wrapper for that.

anyone out there got javacv to run?
Top Expert 2016
Commented:
/opt/local/lib/ is NOT on java.library.path (unless it's symlinked) so nothing in there will be found by Java. You need to put that directory on it

Author

Commented:
As mentioned above I have tried to set the environment variable DYLD_FALLBACK_LIBRARY_PATH with the value: ${env_var:/opt/local/lib/} but there are other variable types to choose from, perhaps I am using the wrong one?
Top Expert 2016

Commented:
That's not the point i made. I'm talking about java.library.path
brilliant! Ok so it turns out that i was trying to add the environment variable to the run/debug configurations but instead i needed to go into project->properties->java build path->Add Variable

and proceed with adding DYLD_FALLBACK_LIBRARY_PATH with value /opt/local/lib/

Thanks for helping me track that down! hopefully others can learn from my mistake!
Top Expert 2016

Commented:
:)

Author

Commented:
because it explains why it did not work in the first place, though the points go to who pointed to the right place

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial