以下文件基本上是从我从ROS网站获得的脚本自动生成的,除了我修改了一些opencv相关软件包以便它们适合我的ROS项目。使用Ctrl-F +“opencv”,您可以在变量“stlibs”中找到这些名称。
当我使用NDK将opencv-3.3.1链接到开源ROS项目时发生错误。我从opencv静态库中得到了许多“未定义的引用”错误,但那些引用的函数应该打包在其他opencv .a文件中,对吧?
所以我想知道...... Android.mk中prebuilt_static_libraries的顺序是否重要?如果是这样,任何人都可以帮助我吗?
/ path / to / the / file / ros-android-ndk 中的相关Android.mk:
LOCAL_PATH := $(call my-dir)
# These must go in some sort of order like include flags, otherwise they are dropped
# Oh no, need to automate this with catkin somehow....
stlibs := roscpp boost_signals boost_filesystem rosconsole \
rosconsole_print rosconsole_backend_interface boost_regex xmlrpcpp \
roscpp_serialization rostime boost_date_time cpp_common boost_system \
boost_thread console_bridge move_base rotate_recovery global_planner \
navfn layers boost_iostreams qhullstatic flann_cpp_s flann_cpp_s-gd \
nodeletlib bondcpp uuid rosbag rosbag_storage roslz4 lz4 topic_tools \
voxel_grid tf tf2_ros actionlib tf2 move_slow_and_clear \
dwa_local_planner clear_costmap_recovery carrot_planner \
base_local_planner trajectory_planner_ros urdfdom_sensor \
urdfdom_model_state urdfdom_model urdfdom_world rosconsole_bridge \
pointcloud_filters laser_scan_filters mean params increment median \
transfer_function compressed_image_transport cv_bridge image_transport \
compressed_depth_image_transport amcl_sensors amcl_map amcl_pf \
stereo_image_proc image_proc image_geometry ***opencv_imgproc \
opencv_core opencv_flann opencv_highgui opencv_features2d opencv_ml \
opencv_imgcodecs opencv_calib3d opencv_video opencv_objdetect \
opencv_photo opencv_videostab opencv_superres opencv_stitching \
opencv_dnn opencv_shape opencv_videoio*** cpufeatures IlmImf libjasper \
libjpeg libpng libprotobuf libtiff libwebp tbb tegra_hal polled_camera \
camera_info_manager collada_parser geometric_shapes octomap octomath \
shape_tools random_numbers camera_calibration_parsers costmap_2d \
laser_geometry message_filters resource_retriever \
dynamic_reconfigure_config_init_mutex tinyxml class_loader \
PocoFoundation roslib rospack boost_program_options pcl_ros_filters \
pcl_ros_io pcl_ros_tf pcl_common pcl_octree pcl_kdtree pcl_search \
pcl_sample_consensus pcl_filters pcl_io pcl_features pcl_registration \
pcl_keypoints pcl_ml pcl_segmentation pcl_stereo pcl_tracking \
pcl_recognition pcl_surface pluginlib pluginlib_tutorials \
image_transport_plugins nodelet_math yaml-cpp
#shlibs :=
define include_shlib
$(eval include $$(CLEAR_VARS))
$(eval LOCAL_MODULE := $(1))
$(eval LOCAL_SRC_FILES := $$(LOCAL_PATH)/lib/lib$(1).so)
$(eval include $$(PREBUILT_SHARED_LIBRARY))
endef
define include_stlib
$(eval include $$(CLEAR_VARS))
$(eval LOCAL_MODULE := $(1))
$(eval LOCAL_SRC_FILES := $$(LOCAL_PATH)/lib/lib$(1).a)
$(eval include $$(PREBUILT_STATIC_LIBRARY))
endef
#$(foreach shlib,$(shlibs),$(eval $(call include_shlib,$(shlib))))
$(foreach stlib,$(stlibs),$(eval $(call include_stlib,$(stlib))))
include $(CLEAR_VARS)
LOCAL_MODULE := roscpp_android_ndk
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_EXPORT_CPPFLAGS := -fexceptions -frtti
#LOCAL_SRC_FILES := dummy.cpp
LOCAL_EXPORT_LDLIBS := $(foreach l,$(shlibs),-l$(l)) -L$(LOCAL_PATH)/lib
#LOCAL_EXPORT_LDLIBS := -lstdc++ #-L$(LOCAL_PATH)/lib
#LOCAL_SHARED_LIBRARIES := $(shlibs)
LOCAL_STATIC_LIBRARIES := $(stlibs) gnustl_static
include $(BUILD_STATIC_LIBRARY)
错误消息如下,
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(calibration.cpp.o):calibration.cpp:function icvGetRectangles(CvMat const*, CvMat const*, CvMat const*, CvMat const*, CvSize, cv::Rect_<float>&, cv::Rect_<float>&): error: undefined reference to 'cvUndistortPoints'
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(calibration.cpp.o):calibration.cpp:function cvRodrigues2: error: undefined reference to 'cv::checkRange(cv::_InputArray const&, bool, cv::Point_<int>*, double, double)'
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(calibration.cpp.o):calibration.cpp:function cvFindExtrinsicCameraParams2: error: undefined reference to 'cvUndistortPoints'
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(calibration.cpp.o):calibration.cpp:function cvFindExtrinsicCameraParams2: error: undefined reference to 'cvCheckArr'
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(calibration.cpp.o):calibration.cpp:function cvStereoRectify: error: undefined reference to 'cvUndistortPoints'
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(calibration.cpp.o):calibration.cpp:function cv::rectify3Collinear(cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::Size_<int>, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, double, cv::Size_<int>, cv::Rect_<int>*, cv::Rect_<int>*, int): error: undefined reference to 'cv::undistortPoints(cv::_InputArray const&, cv::_OutputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&)'
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(calibration.cpp.o):calibration.cpp:function cv::rectify3Collinear(cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::Size_<int>, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, double, cv::Size_<int>, cv::Rect_<int>*, cv::Rect_<int>*, int): error: undefined reference to 'cv::undistortPoints(cv::_InputArray const&, cv::_OutputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&)'
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(ptsetreg.cpp.o):ptsetreg.cpp:function cv::PointSetRegistrator::~PointSetRegistrator(): error: undefined reference to 'cv::Algorithm::~Algorithm()'
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(ptsetreg.cpp.o):ptsetreg.cpp:function cv::PointSetRegistrator::~PointSetRegistrator(): error: undefined reference to 'cv::Algorithm::~Algorithm()'
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(ptsetreg.cpp.o):ptsetreg.cpp:function cv::LMeDSPointSetRegistrator::~LMeDSPointSetRegistrator(): error: undefined reference to 'cv::Algorithm::~Algorithm()'
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(ptsetreg.cpp.o):ptsetreg.cpp:function cv::LMeDSPointSetRegistrator::~LMeDSPointSetRegistrator(): error: undefined reference to 'cv::Algorithm::~Algorithm()'
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(ptsetreg.cpp.o):ptsetreg.cpp:function cv::createRANSACPointSetRegistrator(cv::Ptr<cv::PointSetRegistrator::Callback> const&, int, double, double, int): error: undefined reference to 'cv::Algorithm::Algorithm()'
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(ptsetreg.cpp.o):ptsetreg.cpp:function cv::createLMeDSPointSetRegistrator(cv::Ptr<cv::PointSetRegistrator::Callback> const&, int, double, int): error: undefined reference to 'cv::Algorithm::Algorithm()'
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(ptsetreg.cpp.o):ptsetreg.cpp:typeinfo for cv::PointSetRegistrator: error: undefined reference to 'typeinfo for cv::Algorithm'
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(ptsetreg.cpp.o):ptsetreg.cpp:vtable for cv::PointSetRegistrator: error: undefined reference to 'cv::Algorithm::save(cv::String const&) const'
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(ptsetreg.cpp.o):ptsetreg.cpp:vtable for cv::PointSetRegistrator: error: undefined reference to 'cv::Algorithm::getDefaultName() const'
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(ptsetreg.cpp.o):ptsetreg.cpp:vtable for cv::RANSACPointSetRegistrator: error: undefined reference to 'cv::Algorithm::save(cv::String const&) const'
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(ptsetreg.cpp.o):ptsetreg.cpp:vtable for cv::RANSACPointSetRegistrator: error: undefined reference to 'cv::Algorithm::getDefaultName() const'
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(ptsetreg.cpp.o):ptsetreg.cpp:vtable for cv::LMeDSPointSetRegistrator: error: undefined reference to 'cv::Algorithm::save(cv::String const&) const'
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(ptsetreg.cpp.o):ptsetreg.cpp:vtable for cv::LMeDSPointSetRegistrator: error: undefined reference to 'cv::Algorithm::getDefaultName() const'
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(solvepnp.cpp.o):solvepnp.cpp:function cv::solvePnP(cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, bool, int): error: undefined reference to 'cv::undistortPoints(cv::_InputArray const&, cv::_OutputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&)'
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(solvepnp.cpp.o):solvepnp.cpp:function cv::solvePnP(cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, bool, int): error: undefined reference to 'cv::undistortPoints(cv::_InputArray const&, cv::_OutputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&)'
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(levmarq.cpp.o):levmarq.cpp:function cv::createLMSolver(cv::Ptr<cv::LMSolver::Callback> const&, int): error: undefined reference to 'cv::Algorithm::Algorithm()'
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(levmarq.cpp.o):levmarq.cpp:typeinfo for cv::LMSolver: error: undefined reference to 'typeinfo for cv::Algorithm'
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(levmarq.cpp.o):levmarq.cpp:vtable for cv::LMSolver: error: undefined reference to 'cv::Algorithm::save(cv::String const&) const'
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(levmarq.cpp.o):levmarq.cpp:vtable for cv::LMSolver: error: undefined reference to 'cv::Algorithm::getDefaultName() const'
/home/csx/ros-android-ndk/roscpp_android/output/roscpp_android_ndk/lib/libopencv_calib3d.a(triangulate.cpp.o):triangulate.cpp:function cvCorrectMatches: error: undefined reference to 'cvSolvePoly'
答案 0 :(得分:1)
是的,链接器的成功取决于静态库的顺序。请参阅https://github.com/android-ndk/ndk/issues/545及其中的一些解决方法,例如
LOCAL_LDLIBS += -Wl,--start-group -L $(TARGET_OUT) $(foreach l,$(stlibs),-l $(l)) -Wl,--end-group
-l
和$(l)
之间的空格是有意的,否则NDK会抱怨。
答案 1 :(得分:0)
OpenCV 3.3.x在支持Android NDK R15 +版本时遇到一些问题,您可以在他们的官方changelog中看到,尝试将您的OCV更新到最新版本(3.4.1)并查看问题是否仍然存在。