我正在尝试调试vs代码中的catkin包节点,但是我遇到了一个问题。由于某些原因,在调试中,模式程序在需要从共享库创建对象时中止。当程序无法创建调用堆栈对象时,就有我的共享库(.so),但是vscode说,库有未知的来源,根据我可以得出的结论,cmake或vscode不知道共享库位于何处。CMakeLists.txt中包含了如下共享库:
cmake_minimum_required(VERSION 3.0.2)
## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++14)
project(1_OpenCV_detection)
message(${PROJECT_SOURCE_DIR})
# Aggregate the sources
#file(GLOB SOURCES "${PROJECT_SOURCE_DIR}/include/*.cpp")
set(SOURCES "${PROJECT_SOURCE_DIR}/include/Model.cpp"
"${PROJECT_SOURCE_DIR}/include/Mesh.cpp"
"${PROJECT_SOURCE_DIR}/include/CsvReader.cpp"
"${PROJECT_SOURCE_DIR}/include/CsvWriter.cpp"
"${PROJECT_SOURCE_DIR}/include/ModelRegistration.cpp"
"${PROJECT_SOURCE_DIR}/include/PnPProblem.cpp"
"${PROJECT_SOURCE_DIR}/include/RobustMatcher.cpp"
"${PROJECT_SOURCE_DIR}/include/Utils.cpp")
message(${SOURCES})
#set(OpenCV_DIR "/usr/share/OpenCV/")
set(OpenCV_DIR "/usr/local/lib/cmake/opencv4/")
#message(${OpenCV_DIR})
set(CMAKE_CXX_STANDARD_REQUIRED ON)
## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
include
${opencv_INCLUDE_DIRS}
${catkin_INCLUDE_DIRS}
${OpenCV_DIR}
/usr/local/include/opencv4/opencv2/core/utils/
/usr/local/include/opencv4/opencv2/core/
/usr/local/include/opencv4/opencv2/
/opt/ros/melodic/include/
/usr/include/boost/
#/usr/include/opencv/opencv2/
#/usr/share/OpenCV/
#linux
/usr/include/c++/7/
/usr/include/x86_64-linux-gnu/c++/7/
/usr/include/c++/7/backward/
/usr/lib/gcc/x86_64-linux-gnu/7/include/
#/usr/local/include/
/usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/
/usr/include/x86_64-linux-gnu/
/usr/include/
/usr/local/lib/
)
add_library(opencv_so SHARED IMPORTED GLOBAL)
set_target_properties(
opencv_so
PROPERTIES
IMPORTED_LOCATION /usr/local/lib/libopencv_core.so.4.3
IMPORTED_IMPLIB /usr/local/lib/libopencv_core.so.4.3
)
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
OpenCV REQUIRED
cv_bridge
image_transport
roscpp
sensor_msgs
std_msgs
)
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES 1_OpenCV_detection
CATKIN_DEPENDS cv_bridge image_transport roscpp sensor_msgs std_msgs
# DEPENDS system_lib
)
add_executable(OpenCV_registration src/OpenCV_registration.cpp ${SOURCES} ${OpenCV_DIR})
target_link_libraries(OpenCV_registration ${catkin_LIBRARIES} ${OpenCV_LIBS} opencv_so)
add_executable(test_luka src/test.cpp ${SOURCES} ${OpenCV_DIR})
target_link_libraries(test_luka ${catkin_LIBRARIES} ${OpenCV_LIBS} opencv_so)我已经搜索了谷歌颠倒,但我找不到任何解决方案,如何将共享库包括在我的cmake,为我工作。
我正在调试这个小程序:
// C++
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
// OpenCV
#include <opencv2/core.hpp>
#include <opencv2/core/utils/filesystem.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/calib3d.hpp>
#include <opencv2/video/tracking.hpp>
#include <opencv2/core/utility.hpp>
// PnP Tutorial
#include "Mesh.h"
#include "Model.h"
#include "PnPProblem.h"
#include "RobustMatcher.h"
#include "ModelRegistration.h"
#include "Utils.h"
//ROS-->openCV
//bridge between ROS and opencv; used for reading from camera topic in ROS and giving it to opencv
#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>
/** GLOBAL VARIABLES **/
using namespace cv;
using namespace std;
/** Functions headers **/
void help();
void initKalmanFilter( KalmanFilter &KF, int nStates, int nMeasurements, int nInputs, double dt);
void predictKalmanFilter( KalmanFilter &KF, Mat &translation_predicted, Mat &rotation_predicted );
void updateKalmanFilter( KalmanFilter &KF, Mat &measurements,
Mat &translation_estimated, Mat &rotation_estimated );
void fillMeasurements( Mat &measurements,
const Mat &translation_measured, const Mat &rotation_measured);
string CurrentPath;
string getCurrentPath()
{
size_t size;
char *path=NULL;
path=getcwd(path,size);
CurrentPath=path;
return path;
}
/** Main program **/
int main(int argc, char *argv[])
{
//CommandLineParser parser(argc, argv, keys);
cout << "Current directory is: " << getCurrentPath() << endl;
string video_read_path = samples::findFile("src/1_OpenCV_detection/Data/box.mp4"); // recorded video
string yml_read_path = samples::findFile("src/1_OpenCV_detection/Data/cube_30mm/cube_30mm.yml"); // 3dpts + descriptors
string ply_read_path = samples::findFile("src/1_OpenCV_detection/Data/cube_30mm/meshes/cube_30mm.ply"); // object mesh
Model model; // instantiate Model object
cout<<"Before model.load()"<<endl;
model.load(yml_read_path); // load a 3D textured object model
cout<<"After model.load()"<<endl;
Mesh mesh; // instantiate Mesh object
mesh.load(ply_read_path); // load an object mesh
return 0;
}程序总是在同一个地方失败,在方法model.load(yml_read_path)和vscode中,右下角会弹出窗口,上面写着:
无法打开'strlen-avx2.S':无法读取文件'/build/glibc-OTsEL5/glibc-2.27/sysdeps/x86_64/multiarch/strlen-avx2.S‘(错误:无法解析不存在的文件'/build/glibc-OTsEL5/glibc-2.27/sysdeps/x86_64/multiarch/strlen-avx2.S'). )
但我的观点是,strlen没有问题,而且.so库也不包括在内。
忽略所有这些包括标题,我只是从另一个程序复制它们,但我没有在我的test_luka.cpp中使用它
任何帮助都将不胜感激。
编辑:
我曾经尝试过@Boris (https://github.com/microsoft/vscode-cpptools/issues/811),但是没有任何成功,共享库仍然是未知的,唯一的区别是在异常之后,我的程序会转到strlen-avx2.S。
$ sudo apt install glibc-source
$ cd /usr/src/glibc
$ sudo tar xvf glibc-2.27.tar.xz 然后,使用sourceFileMap在launch.json中创建文件夹链接:
"sourceFileMap": {
"/build/glibc-OTsEL5": "/usr/src/glibc"
},在exe目录中运行ldd时,如下所示:
ldd OpenCV_registration | grep libopencv_core我得到了这个输出:
/usr/lib/x86_64-linux-gnu/libopencv_core.so.3.2 (0x00007f0f4d85e000) libopencv_core.so.3.2 => (0x00007f0f4d85e000) libopencv_core.so.4.3 => /usr/local/lib/libopencv_core.so.4.3 (0x00007f0f0f4bc62000),因此它似乎认识到需要哪些库,但看起来不知道在哪里找到它们。
发布于 2020-05-18 14:13:57
试试vs代码的github https://github.com/microsoft/vscode-cpptools/issues/811中提到的修补程序
发布于 2020-08-04 09:48:21
当我试图将cv_bridge与不兼容的OpenCV版本一起使用(我使用源代码安装方法安装了更高版本的OpenCV )时,我也遇到了同样的错误,请确保您正在链接到与您使用的ROS版本捆绑在一起的OpenCV。
https://stackoverflow.com/questions/61871156
复制相似问题