构建OpenCV时出错:"使用-fPIC重新编译"

时间:2017-11-30 21:00:11

标签: c++ linux opencv makefile ant

我在本指南http://opencv-java-tutorials.readthedocs.io/en/latest/01-installing-opencv-for-java.html

的帮助下在Linux上安装OpenCV

在最后一步,我收到了以下错误。我试图在 cmake-gui 中添加fPIC,但仍然没有解决问题。在cmake-gui中,我创建了一个新的名称 - 值条目:CXX_FLAG -fPIC - 不确定这是否是正确的方法。

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

更新: cmake-gui中的正确标志是CMAKE_CXX_FLAGS。在configure, generate and make -j之后,仍然没有错误消失。

1 个答案:

答案 0 :(得分:1)

行。这对我有用。

$ 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