我正在尝试安装OpenCV以用于Python。第一次安装很顺利;但是,我错过了cv2.so
文件。然后我添加了-D BUILD_NEW_PYTHON_SUPPORT=ON
,希望它能为我创建cv2.so
文件。
完整命令:
cmake -D CMAKE_INSTALL_PREFIX=${target} -D CMAKE_FIND_ROOT_PATH=${target} -D CMAKE_BUILD_TYPE=RELEASE -D BUILD_NEW_PYTHON_SUPPORT=ON -D BUILD_SHARED_LIBS=OFF -D CMAKE_SHARED_LINKER_FLAGS="-fPIC" ..
大约92%,OpenCV失败并发生以下情况:
Scanning dependencies of target opencv_python
[ 92%] Building CXX object modules/python/CMakeFiles/opencv_python.dir/src2/cv2.cpp.o
Linking CXX shared library ../../lib/cv2.so
/usr/bin/ld: /usr/local/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libpython2.7.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[2]: *** [lib/cv2.so] Error 1
make[1]: *** [modules/python/CMakeFiles/opencv_python.dir/all] Error 2
make: *** [all] Error 2
ERROR: Build failed, exited 2
运行Heroku安装的默认版本的Python 2.7.6。我发现了一些帖子,表明需要python-dev
,但看起来dev头已经存在(Screenshot)。
我正在使用自定义buildpack,如果有任何帮助的话。
答案 0 :(得分:2)
显然,Python需要使用传入的--enable-shared
标志进行编译,以便创建libpython2.7.so
和libpython2.7.so.1.0
。使用Python模块的OpenCV需要libpython2.7.so
。
要修复,请从源代码编译python:
./configure --enable-shared
make
make install
确保在编译OpenCV时传入-D BUILD_NEW_PYTHON_SUPPORT=ON
CMake标志。