Reputation: 2877
I am installing OpenCV on Linux with the help of this guide http://opencv-java-tutorials.readthedocs.io/en/latest/01-installing-opencv-for-java.html
At the last step I got the following error. I have tried to add fPIC
in cmake-gui but still didnt solve the problem. In cmake-gui, I created a new name-value entry: CXX_FLAG -fPIC
-- not exactly sure if this would be the right way to do it.
make -j
Linking CXX shared library ../../lib/libopencv_java331.so
/usr/bin/ld: CMakeFiles/opencv_java.dir/generator/src/cpp/listconverters.cpp.o: relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
CMakeFiles/opencv_java.dir/generator/src/cpp/listconverters.cpp.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [lib/libopencv_java331.so] Error 1
make[1]: *** [modules/java/CMakeFiles/opencv_java.dir/all] Error 2
make: *** [all] Error 2
UPDATE:
The correct flag in cmake-gui is CMAKE_CXX_FLAGS. Still error doesn't go away after configure, generate and make -j
.
Upvotes: 1
Views: 554
Reputation: 2877
OK. Here's what worked for me.
$ export JAVA_HOME=/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64 //replace with your JDK path
$ git clone https://github.com/opencv/opencv.git
$ cd opencv
$ mkdir build
$ cd build
$ cmake -D BUILD_SHARED_LIBS=OFF -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=. ..
$ make -j
BUILD SUCCESSFUL
Total time: 10 seconds
Upvotes: 1