5

Following directions from http://docs.opencv.org/2.4.4-beta/doc/tutorials/introduction/desktop_java/java_dev_intro.html, I am running into the this:

make -j8
...
...
Linking CXX shared library ../../lib/libopencv_java244.dylib
ld: unknown option: -whole-archive
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: * [lib/libopencv_java244.dylib] Error 1
make[1]: *
[modules/java/CMakeFiles/opencv_java.dir/all] Error 2
make: *** [all] Error 2

Any suggestions?

mantithetical
  • 1,755
  • 2
  • 16
  • 21

4 Answers4

22

One of the easiest solution to install OpenCV is to use Homebrew.

All what you need to do is just type:

brew tap homebrew/science
brew install opencv --with-java

It will automaticaly load needed libs and build opencv.

When it will be done, you will be able to find a jar file in

/usr/local/Cellar/opencv/2.4.9/share/OpenCV/java/

opencv path

rayryeng
  • 102,964
  • 22
  • 184
  • 193
Alex
  • 1,986
  • 22
  • 23
  • Awesome. Thank you for this. I installed OpenCV via homebrew as well. I just wanted to know where the JAR file was. +1. – rayryeng Apr 06 '15 at 15:18
4

I'm guessing you're building from source. If so, I recommend using CMake. I've managed to build OpenCV 2.4.4 with the Java module by enabling it using ccmake:

cd OpenCV-2.4.4
mkdir build
cd build
ccmake ..

Make sure BUILD_opencv_java is ON (should be on by default) OpenCV java

After you're done with the settings:

  1. press configure(c)
  2. press generate(g)
  3. continue with the usual make, make install

For convenience I've also uploaded the Java wrapper built for x86_64 on osx 10.8:

George Profenza
  • 50,687
  • 19
  • 144
  • 218
  • Could you link the Java wrapper for opencv 2.4.11 (32 bit version) compiled with JDK 1.6? (http://stackoverflow.com/questions/34103709/build-opencv-jdk-6-32-bit-for-mac?noredirect=1#comment55959146_34103709) – Luke Taylor Dec 05 '15 at 13:07
  • How do you initialise the native library with 2.4.4 seeing that you cannot call System.loadLibrary(Core.NATIVE_LIBRARY_NAME); ? – Luke Taylor Dec 05 '15 at 13:08
4

My Solution for this was to use MacPort installation ... it put every thing you need and you have no worries about config , builds and so on...

Just Install MacPort and then run: "sudo port install opencv +java"

for more details see: http://ladstatt.blogspot.com.br/2013/04/opencv-on-macosx-with-java-support.html

manoel
  • 41
  • 2
2

I had literally the exact same problem! With some digging, I found that the linker ld has different flags in Unix and OS X. Thus the error:

ld: unknown option: -whole-archive

To fix, you can edit the file modules/java/CMakeLists.txt to use the OS X flags. (search for -whole-archive)

Original:

target_link_libraries(${the_module} -Wl,-whole-archive ${__deps} -Wl,-no-whole-archive ${__extradeps} ${OPENCV_LINKER_LIBS})

New:

foreach(_dep ${__deps})
  target_link_libraries(${the_module} -Wl,-force_load "${_dep}")
endforeach()

I'm going to see if I can get these changes into the repo. :)

--Edit--
My original answer was slightly wrong (but partly right!); I've changed the answer above. -force_load only works for one archive, thus the foreach. As well, it should go to the linker, thus the -Wl. See pull request 741 for details and git pull for up-to-date code.

greenbeansugar
  • 300
  • 1
  • 3
  • 9