/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 import"); return NUMPY_IMPORT_ARRAY_RETVAL; } }
Reason: the code calls opencv4, the latest version of cv_bridge also uses opencv4, but the system uses python2 by default
Multiple different python and opencv versions are installed in the system
The corresponding version recognized by cv_bridged during compilation is as follows:
Print out the library version information by adding the following code to the cmakelists.txt of cv_bridge:
# 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("##############################################")
solution:
Modify python related variables from the default version 2 to version 3
In the cmakelists.txt file of the cv_bridge package, add the following code:
set(PYTHON_NUMPY_INCLUDE_DIR ~/.local/lib/python3.6/site-packages/numpy/core/include)
set(PYTHON_INCLUDE_PATH /usr/include/python3.6)
View the numpy storage directory through the command pip3 show numpy
python3 -V view python3 installation directory
A new error occurred:
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
Solution: Add soft connection
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