cv_bridge与python版本问题导致编译错误error: return-statement with no value, in function returning ‘void*’ [-fpe

 

/usr/include/python2.7/numpy/__multiarray_api.h:1537:144: error: return-statement with no value, in function returning ‘void*’ [-fpermissive]
 #define import_array() {if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to imcv_bridge与python版本问题导致编译错误error: return-statement with no value, in function returning ‘void*’ [-fpe_第1张图片port"); return NUMPY_IMPORT_ARRAY_RETVAL; } }

 

原因:代码调用了opencv4,对应最新版本cv_bridge也使用了opencv4,但是系统默认使用了python2

系统中安装了多个不同python及opencv版本

cv_bridged编译时识别到的对应版本如下:

cv_bridge与python版本问题导致编译错误error: return-statement with no value, in function returning ‘void*’ [-fpe_第2张图片

通过在cv_bridge的cmakelists.txt中加入以下代码将库版本信息打印出来:

# Print some message showing some of them
message("##############################################")
message(STATUS "OpenCV library status:")
message(STATUS "    version: ${OpenCV_VERSION}")
message(STATUS "    libraries: ${OpenCV_LIBRARIES}")
message(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}")
message("##############################################")

# Print some message showing some of them
message("##############################################")
message(STATUS "PYTHON library status:")
message(STATUS "    PYTHON_VERSION_MAJOR: ${PYTHON_VERSION_MAJOR}")
message(STATUS "    PYTHON_VERSION_MINOR: ${PYTHON_VERSION_MINOR}")
message(STATUS "    include path: ${PYTHON_NUMPY_INCLUDE_DIR}")
message("##############################################")

cv_bridge与python版本问题导致编译错误error: return-statement with no value, in function returning ‘void*’ [-fpe_第3张图片

 

解决方案:

修改python相关变量从默认的2版本到3版本

cv_bridge包cmakelists.txt文件中,增加以下代码:

set(PYTHON_NUMPY_INCLUDE_DIR ~/.local/lib/python3.6/site-packages/numpy/core/include)
set(PYTHON_INCLUDE_PATH /usr/include/python3.6)

通过指令pip3 show numpy来查看numpy存放目录

python3 -V查看python3安装目录

 

出现新的错误:

make[2]: *** No rule to make target '/usr/lib/x86_64-linux-gnu/libboost_python37.so', needed by '/home/chenlu/uuv/devel/lib/python2.7/dist-packages/cv_bridge/boost/cv_bridge_boost.so'.  Stop.
CMakeFiles/Makefile2:8771: recipe for target 'vision_opencv/cv_bridge/src/CMakeFiles/cv_bridge_boost.dir/all' failed
make[1]: *** [vision_opencv/cv_bridge/src/CMakeFiles/cv_bridge_boost.dir/all] Error 2

解决方案:添加软连接

chenlu@chenlupc:/usr/lib/x86_64-linux-gnu$ sudo ln -s libboost_python-py36.so libboost_python37.so
chenlu@chenlupc:/usr/lib/x86_64-linux-gnu$ sudo ln -s libboost_python-py36.a libboost_python37.a

 

 

 

你可能感兴趣的:(cv_bridge与python版本问题导致编译错误error: return-statement with no value, in function returning ‘void*’ [-fpe)