Building OpenCV with Java Support on Mac OS X (64-

2020-07-13 07:47发布

问题:

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?

回答1:

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.



回答2:

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/



回答3:

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)

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:

  • libopencv_java.dylib
  • opencv-2.4.4.jar
  • opencv-2.4.4.jar.dephelper


回答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



标签: opencv