Federico Jurio
Federico Jurio

Reputation: 68

Qt+OpenCV on Ubuntu won't run/debug: Failed to start application

Im trying to run/debug a simple sample of OpenCV with Qt Creator without success

ENVIRONMENT

Ubuntu 12.04 (64 bit)

Qt Creator 3.0.0 Based on Qt 5.2.0 (64 bit)

OpenCV 2.4.8

SOURCE

main.cpp

#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

void help() {
    cout <<"\nDemonstrate Canny edge detection\n"<< endl;
}

int edgeThresh = 1;
Mat image, gray, edge, cedge;

// define a trackbar callback
void onTrackbar(int, void*) {
    blur(gray, edge, Size(3,3));
    // Run the edge detector on grayscale
    Canny(edge, edge, edgeThresh, edgeThresh*3, 3);
    cedge = Scalar::all(0);
    image.copyTo(cedge, edge);
    imshow("Edge map", cedge);
}

int main( int argc, char** argv ) {
    //QCoreApplication a(argc, argv);
    char* filename = argc == 2 ? argv[1] : (char*)"fruits.jpg";
    image = imread(filename, 1);
    if(image.empty()) {
        //help();
        return -1;
    }
    help();
    cedge.create(image.size(), image.type());
    cvtColor(image, gray, CV_BGR2GRAY);
    // Create a window
    namedWindow("Edge map", 1);
    // create a toolbar
    createTrackbar("Canny threshold", "Edge map", &edgeThresh, 100, onTrackbar);
    // Show the image
    onTrackbar(0, 0);
    // Wait for a key stroke; the same function arranges events processing
    waitKey(0);
    return 0;
    //return a.exec();
}

FirstQtProject.pro

#-------------------------------------------------
#
# Project created by QtCreator 2014-01-13T22:34:52
#
#-------------------------------------------------

QT       += core

QT       -= gui

TARGET = FirstQtProject
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app


SOURCES += main.cpp

INCLUDEPATH += "/usr/local/include/opencv2"

LIBS += `pkg-config --cflags --libs opencv`

BUILD INFORMATION

20:45:14: Running steps for project FirstQtProject...
20:45:14: Configuration unchanged, skipping qmake step.
20:45:14: Starting: "/usr/bin/make" 
g++ -c -pipe -g -Wall -W -D_REENTRANT -fPIE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_CORE_LIB -I../../Qt5.2.0/5.2.0/gcc_64/mkspecs/linux-g++ -I../FirstQtProject -I/usr/local/include/opencv2 -I../../Qt5.2.0/5.2.0/gcc_64/include -I../../Qt5.2.0/5.2.0/gcc_64/include/QtCore -I. -I. -o main.o ../FirstQtProject/main.cpp
g++ -Wl,-rpath,/home/f/Qt5.2.0/5.2.0/gcc_64 -Wl,-rpath,/home/f/Qt5.2.0/5.2.0/gcc_64/lib -o FirstQtProject main.o   `pkg-config --cflags --libs opencv` -L/home/f/Qt5.2.0/5.2.0/gcc_64/lib -lQt5Core -lpthread 
{ test -n "" && DESTDIR="" || DESTDIR=.; } && test $(gdb --version | sed -e 's,[^0-9][^0-9]*\([0-9]\)\.\([0-9]\).*,\1\2,;q') -gt 72 && gdb --nx --batch --quiet -ex 'set confirm off' -ex "save gdb-index $DESTDIR" -ex quit 'FirstQtProject' && test -f FirstQtProject.gdb-index && objcopy --add-section '.gdb_index=FirstQtProject.gdb-index' --set-section-flags '.gdb_index=readonly' 'FirstQtProject' 'FirstQtProject' && rm -f FirstQtProject.gdb-index || true
20:45:16: The process "/usr/bin/make" exited normally.
20:45:16: Elapsed time: 00:01.

ERRORS

Run the project without "Run in terminal" unchecked

Starting /home/f/workspace/build-FirstQtProject-Desktop_Qt_5_2_0_GCC_64bit-Debug/FirstQtProject...

Demonstrate Canny edge detection

The program has unexpectedly finished.
/home/f/workspace/build-FirstQtProject-Desktop_Qt_5_2_0_GCC_64bit-Debug/FirstQtProject crashed

Run the project without "Run in terminal" checked

https://i.sstatic.net/fAegn.jpg

Debug

https://i.sstatic.net/eJu4x.jpg

Upvotes: 2

Views: 670

Answers (1)

mp so
mp so

Reputation: 108

On Ubuntu versions after 10.10 you'll run into this in more related applications, such as QtCreator. It is a security feature of Ubuntu that prevent the debugger to attach to processes not owned by him.

This is filed as a bug #3509 against QtCreator. To work around this issue, do this:

  • temporary solution (won't survive a reboot):

     echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
    
  • In a file /etc/sysctl.d/10-ptrace.conf (should already exist), change the value of kernel.yama.ptrace_scope to 0 and then reload the configuration: sudo sysctl -p.

I'm explicitly posting the temporary solution, as you probably don't want to keep this feature disabled on a regular machine for security reasons.

Upvotes: 3

Related Questions