Building OpenCV with Java Support on Mac OS X (64-bit)-Collection of common programming errors

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.

Originally posted 2013-11-06 03:16:43.