Ask Your Question
0

catkin_make not working after VS Code ROS extension debug setup

asked 2021-08-27 15:50:36 -0600

msantos gravatar image

updated 2021-08-29 06:14:50 -0600

Hi,

I installed today the VS Code ROS extension, in order to try to debug my code for a ROS node for RGB-D Odometry using OpenCV, which is generating segmentation error (core dumped) when running. I made several changes followed by catkin_make yesterday, until I decided to try a debugger. The only change I made today was to config the ROS extension, as per this tutorial.

After some unsuccessful trials to find the issue with the debugger, I tried to make one change in my code, and build again. And I am now having the following error:

-- +++ processing catkin package: 'test_opencv_pkg'
-- ==> add_subdirectory(test_opencv_pkg)
-- Could NOT find OpenCV (missing: OpenCV_DIR)
-- Could not find the required component 'OpenCV'. The following CMake error indicates that you either need to install the package with the same name or change your environment so that it can be found.
CMake Error at /opt/ros/melodic/share/catkin/cmake/catkinConfig.cmake:83 (find_package):
  Could not find a package configuration file provided by "OpenCV" with any
  of the following names:

    OpenCVConfig.cmake
    opencv-config.cmake

  Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
  "OpenCV_DIR" to a directory containing one of the above files.  If "OpenCV"
  provides a separate development package or SDK, be sure it has been
  installed.
Call Stack (most recent call first):
  test_opencv_pkg/CMakeLists.txt:5 (find_package)


-- Configuring incomplete, errors occurred!
...
Makefile:754: recipe for target 'cmake_check_build_system' failed
make: *** [cmake_check_build_system] Error 1
Invoking "make cmake_check_build_system" failed

I could not understand very well by the error log what can be done for fixing it. Appreciate if some can help to fix it.

Thanks.

Edit:

Adding CMakeLists.txt from my OpenCV Package. I could also notice that after trying build/debug with the mentioned VS Code stuff, I now have lots of new folders/files inside the package folder, such as "catkin", "catkin_generated", "test_results", "CMakeCache.txt", "CTestConfiguration.ini"...

cmake_minimum_required(VERSION 3.0.2)

project(test_opencv_pkg)

find_package(catkin REQUIRED COMPONENTS
  cv_bridge
  rospy
  roscpp
  image_transport
  sensor_msgs
  std_msgs
  OpenCV 
)
if (OpenCV_FOUND)
    message("Find your opencv succesfully")
else()
    message("Cannot find your opencv, please specifiy your opencv path")
    set(OpenCV_INCLUDE_DIRS /opt/opencv/release/include)
    set(OpenCV_LIBS opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs opencv_calib3d)
    link_directories(/opt/opencv/release/lib)
endif()


catkin_package()


include_directories(${catkin_INCLUDE_DIRS}

)


add_executable(opencv_node src/cv_test.cpp)
add_executable(optflow src/optflow.cpp)
add_executable(harris1 src/harris1.cpp)
add_executable(harris2 src/harris1.cpp)
add_executable(opencv_node2 src/cv_test2.cpp)
add_executable(rgbd_odometry src/rgbd_odo.cpp)


target_link_libraries(opencv_node
   ${catkin_LIBRARIES}
 )
target_link_libraries(opencv_node2
   ${catkin_LIBRARIES}
 )

target_link_libraries(rgbd_odometry
   ${catkin_LIBRARIES}
 )
target_link_libraries(optflow
   ${catkin_LIBRARIES}
 )
target_link_libraries(harris1
   ${catkin_LIBRARIES}
 )

target_link_libraries(harris2
   ${catkin_LIBRARIES}
 )
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2021-08-29 15:48:10 -0600

msantos gravatar image

updated 2021-08-29 15:50:08 -0600

I have done fhe following steps and could manage to solve the issue, but not sure if all were needed at all:

  • Removed the ROS, and CMake extensions from VS Code.
  • Removed and reinstalled CMake form my System.
  • Add the following lines before the find_package() in the CMakeLists.txt:

-set(OpenCV_DIR /opt/opencv/release/).

-set(OpenCV_INCLUDE_DIRS /opt/opencv/release/include).

-set(OpenCV_LIBS opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs opencv_calib3d).

Then, I could manage to compile again by using catkin_make.

edit flag offensive delete link more

Comments

While it's possible to use newer OpenCV versions with a ROS release which originally wasn't paired with it, you have to take care of some things. In essence: you now have to build all packages which (transitively) depend on OpenCV yourself.

See #q289264 for a Q&A which discusses PCL, but the same workflow would be needed for OpenCV.

Setting some OpenCV_* CMake variables will not be sufficient to guarantee a stable system.

gvdhoorn gravatar image gvdhoorn  ( 2021-08-30 03:20:22 -0600 )edit

Is there some how to know the most suitable OpenCV version for ROS Melodic/Ubuntu 18 and fix it? I have installed 3.2.0, as mentioned in the comment, and I understood this one should be suitable... however, I am having kind of the same error message (using a debugging trace in my code) as #q352756.

msantos gravatar image msantos  ( 2021-09-01 13:41:45 -0600 )edit
0

answered 2021-08-27 18:37:00 -0600

Mike Scheutzow gravatar image

updated 2021-08-29 13:43:31 -0600

It eventually becomes clear that you have compiled and installed some random version of opencv in ubuntu 18. This is a bad idea in ros. Each release of ros depends on a specific version of opencv. Installing a different version than expected will very likely cause future conflicts if you try to use any opencv-related binary packages from the ros repositories.

I have no suggestions for how you get catkin_make to see that self-compiled library.

Earlier answer:

It could be caused by python2 / python3 confusion.

Have you made sure that your PYTHONPATH env variable has no python3 directories in it?

Have you checked that Visual Studio is configured for python2; see @Ranjit Kathiriya answer to #q385096 from a few days ago.

edit flag offensive delete link more

Comments

Thanks for supporting. Unfortunately it not solved the issue for me, despite the python interpreter was actually pointing to python3.

Also tried samarth's inputs from #q282295, but no changes at all. My main interest was the debugger option than intelisense. If I can manage to revert to previous state before setting up ROS extension (i.g. able to use catkin_make to build after code changing) it will be great by now.

msantos gravatar image msantos  ( 2021-08-28 03:32:00 -0600 )edit

Have you cleaned the workspace to do a full rebuild? catkin can get confused by previous compile errors.

Is the file /usr/share/OpenCV/OpenCVConfig.cmake on your system? This is installed by apt pkg libopencv-dev.

If neither of these is the problem, please edit your question to add your CMakeLists.txt file. Format it using the 101010 button.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-08-28 07:30:16 -0600 )edit

I looked at your links. I don't know exactly what this catkin config command is doing, but you may have switched yourself to using the catkin build toolset. catkin build and catkin_make are not compatible - you must choose one or the other to do your builds. See question #q243192

Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-08-28 07:50:14 -0600 )edit

Thank you for your inputs, going to check it. Please find the CMakeLists.txt from my package in the Edit, which was working quite OK before trying the VS Code debugging set. Regarding OpenCV, I have installed from this Tutorial . The address for the OpenCVConfig is added in the CMakeLists.

msantos gravatar image msantos  ( 2021-08-29 06:18:24 -0600 )edit

Regarding catkin_make vc catkin build, I tried the catkin build command to see how it goes, and got the message below:

The build space at '/home/user/Documents/ROS/cv2_ws/build' was previously built by 'catkin_make'. Please remove the build space or pick a different build space.

You mentioned about clean the workspace and rebuild. I did not try it, but created a new WS with the same CMakeLists.txt and same source files, the error is still there.
I will try this cleaning process,

msantos gravatar image msantos  ( 2021-08-29 06:29:58 -0600 )edit

What do you mean by "my opencv package"? In the past, each ROS release expected that you use a specific version of opencv. I don't know if this is still true for melodic, but it likely is. Why are you not using the libopencv-dev from apt?

Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-08-29 07:51:41 -0600 )edit

Probably I tried without the "dev" suffix, and it not worked. Then I googled and found that tutorial. And by "my open cv pkg" I meant the package which I put the Cmakelists in the question.

msantos gravatar image msantos  ( 2021-08-29 11:29:41 -0600 )edit

Funny thing here: I made the following:

-catkin clean
-catkin config

then navigate to the pkg folder and:

cmake -DOpenCV_DIR=/opt/opencv/release ..

then back to the workspace folder and catkin_make. It could build well. But just ignored the package and ROS cannot find it.

msantos gravatar image msantos  ( 2021-08-29 12:57:19 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2021-08-27 15:50:36 -0600

Seen: 107 times

Last updated: Aug 29