Ask Your Question

segmentation fault - program compiles but imediate segfault when starting

asked 2014-10-05 16:39:19 -0500


I am having a problem that is really driving me crazy. I installed opencv and cannot find out what is causing the problem. I copied sample code from the tutorials to test my installation and I get a segfault whenever I start the program.

I reduced the code to identify the cause of the problem:

#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
//#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/nonfree/nonfree.hpp"

using namespace cv;

void readme();

/** @function main */
int main( )
    std::cout << "hello!!!" << std::endl;

  Mat img_1;

  img_1 = imread("eagle.jpg");

  int minHessian = 400;

  SurfFeatureDetector detector( minHessian );

//  std::vector<KeyPoint> keypoints_1, keypoints_2;

//  detector.detect( img_1, keypoints_1 );

  return 0;

imread seems to be the culprit. If I exclude imread("eagle.jpg") it works fine. But if I put it into the code I get a segfault once I execute the code - even before "hello!!!" is printet.

This is where the debugger stops and gives me the segfault - if anybody can read anything from that. -> (0x7fffd492cdfc <+0x0000> lock incl (%rax))

I tried to install different versions of opencv without success.

I am using Ubuntu 14.04 with Qt Creator 3.0.1 and currently opencv 2.8.3

I greatly appreciate any help!


edit retag flag offensive close merge delete


Start by building OpenCV in DEBUG mode instead of RELEASE mode. This way you will get actual error information instead of simple segmentation faults. But best guess is that your linker libraries are probably not connected correctly! Also, OpenCV 2.8.3 doesnt exist, so I guess it is 2.3.8 but why the hell not use the most recent stable version 2.4.9? IT has TONS of fixed bugs!

StevenPuttemans gravatar imageStevenPuttemans ( 2014-10-06 04:40:01 -0500 )edit

You have a double topic [here}( Since this one contains more answers, I will close down the other!

StevenPuttemans gravatar imageStevenPuttemans ( 2014-10-06 04:54:19 -0500 )edit

sorry, thanks for the hint

martin1988 gravatar imagemartin1988 ( 2014-10-16 04:59:36 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2014-10-05 22:20:01 -0500

camlee gravatar image

This code ran just fine for me: no segfault. I'm not sure that means much though. Here's the two things I'd try next:

  1. A different image file than eagle.jpg. I'd expect opencv to handle anything that might be invalid about an input file better than segfaulting, but who knows.

  2. Reduce the includes to a bare minimum: you shouldn't need all of those opencv includes to just do an imread.

edit flag offensive delete link more


It also works for me now. I reinstalled everything and updated my qt creator to 3.2.1

martin1988 gravatar imagemartin1988 ( 2014-10-16 05:10:14 -0500 )edit

Question Tools


Asked: 2014-10-05 16:39:19 -0500

Seen: 530 times

Last updated: Oct 05 '14