- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
(抱歉英语不好,我是德国人)
你好程序员,
理论上,这个简单的 C++ OpenCV 示例应该显示一个 100x100 的黑色图像,等到按下一个键,将“仍在运行!\n”写入错误流并以退出代码 123 退出。
当我运行这个程序时,我看到黑色图像,直到我按下一个键。似乎一切正常,直到我查看终端:
$ ./a.out
still running!
Segmentation fault (Core dumped) #shouldn't happen
$ echo $?
139 #should be 123
$
如果有人能回答我以下问题之一,我将不胜感激: - 为什么这个程序会产生段错误? - 我怎样才能解决这个问题? - 源代码有问题吗?如果不是,哪个库/程序对此错误负责?
我能听到你在尖叫:“但是,嘿,如果它只是在调用 exit/return 时崩溃,那你为什么要关心它呢?程序正常退出或崩溃都没有关系”。你是对的,但我担心导致这个程序在退出时崩溃的同一个错误可能会导致程序在运行时崩溃/导致其他奇怪的问题。
#include <opencv2/opencv.hpp>
#include <iostream>
int main(void) {
{
cv::Mat test(100, 100, CV_8UC1, cv::Scalar(0));
//cv::namedWindow( "testName", cv::WINDOW_NORMAL ); //doesn't help
//cv::namedWindow( "testName", cv::WINDOW_OPENGL ); //doesn't help
cv::imshow( "testName", test );
cv::waitKey(0);
//cv::destroyAllWindows(); //doesn't help
}
std::cerr << "still running!\n";
return 123;
}
编译:
$ g++ `pkg-config --cflags --libs opencv` main.cpp
或
$ g++ -lopencv_core -lopencv_highgui main.cpp
关于我的电脑的一些附加信息:
操作系统:Linux (Fedora 25)
$ cat /proc/version
Linux version 4.8.14-300.fc25.x86_64 (mockbuild@bkernel02.phx2.fedoraproject.org) (gcc version 6.2.1 20160916 (Red Hat 6.2.1-2) (GCC) ) #1 SMP Mon Dec 12 16:31:04 UTC 2016
OpenCV 使用以下命令安装:dnf install -y opencv*
输入 dnf remove opencv 并点击 tab 键产生以下输出:
opencv-3.1.0-8.fc25.x86_64 opencv-devel-3.1.0-8.fc25.x86_64
opencv-contrib-3.1.0-8.fc25.x86_64 opencv-devel-docs-3.1.0-8.fc25.noarch
opencv-core-3.1.0-8.fc25.x86_64 opencv-python-3.1.0-8.fc25.x86_64
更新:
$ valgrind ./a.out
==24083== Memcheck, a memory error detector
==24083== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==24083== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info
==24083== Command: ./a.out
==24083==
^C==24083==
==24083== Process terminating with default action of signal 2 (SIGINT)
==24083== at 0x401B4B5: open (in /usr/lib64/ld-2.24.so)
==24083== by 0x4005547: open_verify.constprop.7 (in /usr/lib64/ld-2.24.so)
==24083== by 0x40090BF: _dl_map_object (in /usr/lib64/ld-2.24.so)
==24083== by 0x400DDFF: openaux (in /usr/lib64/ld-2.24.so)
==24083== by 0x4010873: _dl_catch_error (in /usr/lib64/ld-2.24.so)
==24083== by 0x400E44D: _dl_map_object_deps (in /usr/lib64/ld-2.24.so)
==24083== by 0x4003146: dl_main (in /usr/lib64/ld-2.24.so)
==24083== by 0x401991E: _dl_sysdep_start (in /usr/lib64/ld-2.24.so)
==24083== by 0x4004F67: _dl_start (in /usr/lib64/ld-2.24.so)
==24083== by 0x4000CD7: ??? (in /usr/lib64/ld-2.24.so)
==24083== Jump to the invalid address stated on the next line
==24083== at 0x5A6: ???
==24083== by 0x4005547: open_verify.constprop.7 (in /usr/lib64/ld-2.24.so)
==24083== by 0x40090BF: _dl_map_object (in /usr/lib64/ld-2.24.so)
==24083== by 0x400DDFF: openaux (in /usr/lib64/ld-2.24.so)
==24083== by 0x4010873: _dl_catch_error (in /usr/lib64/ld-2.24.so)
==24083== by 0x400E44D: _dl_map_object_deps (in /usr/lib64/ld-2.24.so)
==24083== by 0x4003146: dl_main (in /usr/lib64/ld-2.24.so)
==24083== by 0x401991E: _dl_sysdep_start (in /usr/lib64/ld-2.24.so)
==24083== by 0x4004F67: _dl_start (in /usr/lib64/ld-2.24.so)
==24083== by 0x4000CD7: ??? (in /usr/lib64/ld-2.24.so)
==24083== Address 0x5a6 is not stack'd, malloc'd or (recently) free'd
==24083==
==24083==
==24083== Process terminating with default action of signal 11 (SIGSEGV)
==24083== Bad permissions for mapped region at address 0x5A6
==24083== at 0x5A6: ???
==24083== by 0x4005547: open_verify.constprop.7 (in /usr/lib64/ld-2.24.so)
==24083== by 0x40090BF: _dl_map_object (in /usr/lib64/ld-2.24.so)
==24083== by 0x400DDFF: openaux (in /usr/lib64/ld-2.24.so)
==24083== by 0x4010873: _dl_catch_error (in /usr/lib64/ld-2.24.so)
==24083== by 0x400E44D: _dl_map_object_deps (in /usr/lib64/ld-2.24.so)
==24083== by 0x4003146: dl_main (in /usr/lib64/ld-2.24.so)
==24083== by 0x401991E: _dl_sysdep_start (in /usr/lib64/ld-2.24.so)
==24083== by 0x4004F67: _dl_start (in /usr/lib64/ld-2.24.so)
==24083== by 0x4000CD7: ??? (in /usr/lib64/ld-2.24.so)
==24083==
==24083== HEAP SUMMARY:
==24083== in use at exit: 0 bytes in 0 blocks
==24083== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==24083==
==24083== All heap blocks were freed -- no leaks are possible
==24083==
==24083== For counts of detected and suppressed errors, rerun with: -v
==24083== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Segmentation fault (Speicherabzug geschrieben)
更新 #2
$ g++ -g `pkg-config --cflags --libs opencv` main.cpp; gdb a.out
GNU gdb (GDB) Fedora 7.12-29.fc25
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.out...done.
(gdb) run
Starting program: /home/volker/Dropbox/Roboter/eclipse/CVS/source/a.out
Missing separate debuginfos, use: dnf debuginfo-install glibc-2.24-3.fc25.x86_64
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[New Thread 0x7fffc86e1700 (LWP 5063)]
[New Thread 0x7fffbd3b9700 (LWP 5072)]
[New Thread 0x7fffb5974700 (LWP 5089)]
[New Thread 0x7fffb5173700 (LWP 5090)]
[New Thread 0x7fffb4972700 (LWP 5091)]
[New Thread 0x7fffa796c700 (LWP 5100)]
still running!
Thread 7 "QDBusConnection" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffa796c700 (LWP 5100)]
0x00007fffefa5601d in QObject::disconnect(QObject const*, char const*, QObject const*, char const*) () from /lib64/libQt5Core.so.5
Missing separate debuginfos, use: dnf debuginfo-install LONG LIST OF PACKAGES
(gdb) backtrace
#0 0x00007fffefa5601d in QObject::disconnect(QObject const*, char const*, QObject const*, char const*) () from /lib64/libQt5Core.so.5
#1 0x00007fffbec6bfb0 in QDBusConnectionPrivate::closeConnection() () from /lib64/libQt5DBus.so.5
#2 0x00007fffbec58852 in QDBusConnectionManager::run() () from /lib64/libQt5DBus.so.5
#3 0x00007fffef88b9da in QThreadPrivate::start(void*) () from /lib64/libQt5Core.so.5
#4 0x00007ffff077e6ca in start_thread () from /lib64/libpthread.so.0
#5 0x00007ffff0a9cf6f in clone () from /lib64/libc.so.6
(gdb)
最佳答案
我用 "gdb"
和 "eclipse-cdt"
调试。
gdb
”运行程序并使用“dnf debuginfo-install”安装调试信息。
"QApplicationPrivate::app_style"
的值和类型。“StylePlugin::~ StylePlugin()”
中设置断点。我确认了
"QLibraryPrivate :: unload ()" will destroy "QApplicationPrivate :: app_style".
"QDBusConnectionPrivate :: closeConnection ()"
应该在 "QLibraryPrivate::unload ()"
之前执行。
此外,我担心 "adwaita::style"
类的基类 "QCommonStyle"
的析构函数不是 "virtual"
.
我还在调查。
关于c++ - 简单的 C++ OpenCV imshow 示例因段错误而崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41240911/
我正在努力实现以下目标, 假设我有字符串: ( z ) ( A ( z ) ( A ( z ) ( A ( z ) ( A ( z ) ( A ) ) ) ) ) 我想编写一个正则
给定: 1 2 3 4 5 6
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
大家好,我卡颂。 Svelte问世很久了,一直想写一篇好懂的原理分析文章,拖了这么久终于写了。 本文会围绕一张流程图和两个Demo讲解,正确的食用方式是用电脑打开本文,跟着流程图、Demo一
身份证为15位或者18位,15位的全为数字,18位的前17位为数字,最后一位为数字或者大写字母”X“。 与之匹配的正则表达式: ?
我们先来最简单的,网页的登录窗口; 不过开始之前,大家先下载jquery的插件 本人习惯用了vs2008来做网页了,先添加一个空白页 这是最简单的的做法。。。先在body里面插入 <
1、MySQL自带的压力测试工具 Mysqlslap mysqlslap是mysql自带的基准测试工具,该工具查询数据,语法简单,灵活容易使用.该工具可以模拟多个客户端同时并发的向服务器发出
前言 今天大姚给大家分享一款.NET开源(MIT License)、免费、简单、实用的数据库文档(字典)生成工具,该工具支持CHM、Word、Excel、PDF、Html、XML、Markdown等
Go语言语法类似于C语言,因此熟悉C语言及其派生语言( C++、 C#、Objective-C 等)的人都会迅速熟悉这门语言。 C语言的有些语法会让代码可读性降低甚至发生歧义。Go语言在C语言的
我正在使用快速将 mkv 转换为 mp4 ffmpeg 命令 ffmpeg -i test.mkv -vcodec copy -acodec copy new.mp4 但不适用于任何 mkv 文件,当
我想计算我的工作簿中的工作表数量,然后从总数中减去特定的工作表。我错过了什么?这给了我一个对象错误: wsCount = ThisWorkbook.Sheets.Count - ThisWorkboo
我有一个 perl 文件,用于查看文件夹中是否存在 ini。如果是,它会从中读取,如果不是,它会根据我为它制作的模板创建一个。 我在 ini 部分使用 Config::Simple。 我的问题是,如果
尝试让一个 ViewController 通过标准 Cocoa 通知与另一个 ViewController 进行通信。 编写了一个简单的测试用例。在我最初的 VC 中,我将以下内容添加到 viewDi
我正在绘制高程剖面图,显示沿路径的高程增益/损失,类似于下面的: Sample Elevation Profile with hand-placed labels http://img38.image
嗨,所以我需要做的是最终让 regStart 和 regPage 根据点击事件交替可见性,我不太担心编写 JavaScript 函数,但我根本无法让我的 regPage 首先隐藏。这是我的代码。请简单
我有一个非常简单的程序来测量一个函数花费了多少时间。 #include #include #include struct Foo { void addSample(uint64_t s)
我需要为 JavaScript 制作简单的 C# BitConverter。我做了一个简单的BitConverter class BitConverter{ constructor(){} GetBy
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
我是 Simple.Data 的新手。但我很难找到如何进行“分组依据”。 我想要的是非常基本的。 表格看起来像: +________+ | cards | +________+ | id |
我现在正在开发一个 JS UDF,它看起来遵循编码。 通常情况下,由于循环计数为 2,Alert Msg 会出现两次。我想要的是即使循环计数为 3,Alert Msg 也只会出现一次。任何想法都
我是一名优秀的程序员,十分优秀!