gpt4 book ai didi

c++ - Ubuntu 上的 Qt+OpenCV 无法运行/调试 : Failed to start application

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:46:43 29 4
gpt4 key购买 nike

我试图用 Qt Creator 运行/调试一个简单的 OpenCV 示例,但没有成功

环境

Ubuntu 12.04(64 位)

Qt Creator 3.0.0 基于 Qt 5.2.0(64 位)

OpenCV 2.4.8

来源

主要.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`

构建信息

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.

错误

在未选中“在终端中运行”的情况下运行项目

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

在不选中“在终端中运行”的情况下运行项目

http://i.stack.imgur.com/fAegn.jpg

调试

http://i.stack.imgur.com/eJu4x.jpg

最佳答案

在 10.10 之后的 Ubuntu 版本中,您将在更多相关应用程序(例如 QtCreator)中遇到此问题。这是 Ubuntu 的一项安全功能,可防止调试器附加到不属于他的进程。

这被归档为 bug #3509 against QtCreator .要解决此问题,请执行以下操作:

  • 临时解决方案(无法在重启后继续存在):

     echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
  • 在文件 /etc/sysctl.d/10-ptrace.conf(应该已经存在)中,更改 kernel.yama.ptrace_scope 的值到 0 然后重新加载配置:sudo sysctl -p

我明确发布了临时解决方案,因为出于安全原因,您可能不想在普通机器上禁用此功能。

关于c++ - Ubuntu 上的 Qt+OpenCV 无法运行/调试 : Failed to start application,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21126688/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com