【发布时间】:2021-02-05 23:04:29
【问题描述】:
所以我遵循了来自https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/helloworld.html 的 ncurses 指南 当我尝试运行编译后的代码时,它会以 Abort 陷阱退出:6 我写的代码
#include <ncurses.h> //Including the NCurses library
int main(){
initscr(); // Initializing the NCurses
printw("Hello world"); // Printing Hello world
refresh(); // Displaying the Window's content on terminal
getch(); // Pausing the program until a key is pressed
endwin(); // Freeing the Terminal from NCurses
return 0;
}
程序的错误
SomeTry(17615,0x118bf35c0) malloc: *** error for object 0xf000000000000000: pointer being freed was not allocated
SomeTry(17615,0x118bf35c0) malloc: *** set a breakpoint in malloc_error_break to debug
Abort trap: 6
lldb 的输出:
SomeTry(17433,0x10010b5c0) malloc: *** error for object 0x14: pointer being freed was not allocated
SomeTry(17433,0x10010b5c0) malloc: *** set a breakpoint in malloc_error_break to debug
Process 17433 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
frame #0: 0x00007fff579c82c6 libsystem_kernel.dylib`__pthread_kill + 10
libsystem_kernel.dylib`__pthread_kill:
-> 0x7fff579c82c6 <+10>: jae 0x7fff579c82d0 ; <+20>
0x7fff579c82c8 <+12>: movq %rax, %rdi
0x7fff579c82cb <+15>: jmp 0x7fff579c2457 ; cerror_nocancel
0x7fff579c82d0 <+20>: retq
Target 0: (SomeTry) stopped.
感谢您对此错误的任何帮助
我尝试过的东西:
removing printw and refresh and getch from the code and compiling and
running it still no luck and also only kept initscr in the main function
and I think it's because of initscr not being able to allocate the memory
but why and how I can resolve them is the question.
我使用的软件:
cmake 3.18.2
llvm Apple LLVM version 10.0.1 (clang-1001.0.46.4)
macOS 10.14.5
ncurses 6.1 from conan-center
conan package manager 1.28.1
【问题讨论】:
-
他们的original example code 对你有用吗?
-
@πάνταῥεῖ 代码不起作用。我将在我的帖子中添加更多信息。
-
ncurses的版本也可能在其中起作用(尽管我不认为它会起作用) - 所以请包含您用来使问题更完整的版本。 -
只有当(例如)OP 混合来自不同开发系统的库时,ncurses 的版本才可能相关。苹果的 ncurses 5.7 副本十多年没有变过。
-
@ThomasDickey 和 TedLyngmo 谢谢,问题来自 ncurses 6.1,安装 ncurses 6.2 解决了问题