ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Strange segfault when running node on raspberry pi 3

asked 2016-08-10 10:30:44 -0600

roach gravatar image

updated 2016-08-11 04:31:32 -0600

Hi all,

I have recently installed ROS kinetic on a raspberry pi 3 (raspbian jessie), as explained in this tutorial.

Everything worked fine (except rviz, but I don't need it). However, when I wanted to test some C++ nodes I wrote on my laptop, it didn't worked.

I just copied my packages in the raspi's catkin_ws, then catkin_maked it. I didn't meet any problem when compiling. The python-coded nodes worked fine, but not the C++ ones. Then I tried to make a very simple C++ node saying hello world, and I build it the same way. And it didn't work (Segmentation Fault). Then I discovered, that if, in the CMakeLists, I did not link the catkin/opencv libraries (with target_link_libraries, which worked on my laptop), the program worked well, but it obviously couldn't interact with ROS/opencv.

Would you have any suggestion, feel free to answer ;)

Thanking you in advance


I have included the codes below. The nodes aims at reading a webcam and sending OpenCV images. It works on my laptop (Ubuntu 16.04, ROS kinetic).

Here is the code :

#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <opencv2/highgui/highgui.hpp>
#include <cv_bridge/cv_bridge.h>
#include <sstream>

int main(int argc, char** argv)
    // Initialization of ROS node and ROS topic
    ros::init(argc, argv, "i_Camera");
    ros::NodeHandle nh;
    image_transport::ImageTransport it(nh);
    image_transport::Publisher pub = it.advertise("/sensors/camera", 1);
    int cam = 0;

    cv::VideoCapture cap(cam);
    // Check if video device can be opened with the given index
    if(!cap.isOpened()) return 1;
    cv::Mat frame;
    sensor_msgs::ImagePtr msg;

    ros::Rate loop_rate(60);

    // Main loop, grab frames and publish them on the topic
    while (nh.ok()) {
        cap >> frame;
        // Check if grabbed frame is not empty
        if(!frame.empty()) {
            msg = cv_bridge::CvImage(std_msgs::Header(), sensor_msgs::image_encodings::BGR8, frame).toImageMsg();


And the CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.3)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

find_package(catkin REQUIRED COMPONENTS


    INCLUDE_DIRS include
    #  LIBRARIES vision
    CATKIN_DEPENDS geometry_msgs roscpp rospy std_msgs visualization_msgs image_transport cv_bridge
    #  DEPENDS system_lib


add_executable(i_Camera src/i_Camera.cpp)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-08-11 09:29:30 -0600

Marcin Bogdanski gravatar image

updated 2016-08-11 09:30:28 -0600

Not a direct answer, but maybe some things to try:

  • Does segfault on any particular line of code?
  • I didn't use rasbian or OpenCV, so this might be complete miss, but maybe try Ubuntu Mate 16.04? It should correspond more closely to what you have on laptop? I have a lot of ROS stuff running or RPi3 with Ubuntu without issues.


edit flag offensive delete link more


Thank you very much for your answer !

Segfault happens when running the node, and I think while loading libraries in memory. I have tried to print something before doing anything else, but it also segfaults.

I'll try Ubuntu Mate right now and keep you informed.

roach gravatar image roach  ( 2016-08-11 10:25:48 -0600 )edit

I have tried with Ubuntu Mate, and it works very well, using exactly the same codes.

roach gravatar image roach  ( 2016-08-18 09:58:24 -0600 )edit

Question Tools


Asked: 2016-08-10 10:30:44 -0600

Seen: 727 times

Last updated: Aug 11 '16