无论我尝试什么,GDB都不能在我的Mac(Mojave)上运行。常见的错误,但我找不到解决方案

问题描述 投票:4回答:1

这是我的第一篇帖子,所以如果我发布错误或格式不正确,我会提前道歉。

我的系统:MacBook Pro运行MacOS Mojave 10.14.1,Netbeans 8.2

我正在运行一个打印hello world的简单C ++程序:

int main(int argc, char** argv) {

    cout << "Hello World" << endl;

    return 0;
}

所以我的问题是我无法使用Netbeans或终端命令在我的MacBook上运行调试器。每次我这样做,我都会收到以下错误:

不是可执行格式:无法识别文件格式

我最初遇到了缺少调试器命令的问题。我按照指示here并安装了Homebrew,获得了gdb,并对gdb二进制文件进行了代码签名。毕竟我开始收到上面突出显示的错误。

我谷歌这个新问题,我发现this stack overflow post表明我可能在64位构建时运行32位gdb。但是,基于运行gdb时的输出:

GNU gdb (GDB) 8.2
Copyright (C) 2018 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-apple-darwin18.0.0".
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"...
BFD: /Users/Anon/Desktop/gdb_test/gdb_test: unknown load command 0x32
BFD: /Users/Anon/Desktop/gdb_test/gdb_test: unknown load command 0x32
"/Users/Anon/Desktop/gdb_test/gdb_test": not in executable format: file format not recognized

和GDB的配置:

This GDB was configured as follows:
   configure --host=x86_64-apple-darwin18.0.0 --target=x86_64-apple-darwin18.0.0
         --with-auto-load-dir=:${prefix}/share/auto-load
         --with-auto-load-safe-path=:${prefix}/share/auto-load
         --with-expat
         --with-gdb-datadir=/usr/local/Cellar/gdb/8.2/share/gdb (relocatable)
         --with-jit-reader-dir=/usr/local/Cellar/gdb/8.2/lib/gdb (relocatable)
         --without-libunwind-ia64
         --without-lzma
         --without-babeltrace
         --without-intel-pt
         --disable-libmcheck
         --without-mpfr
         --with-python=/System/Library/Frameworks/Python.framework/Versions/2.7
         --without-guile
         --with-separate-debug-dir=/usr/local/Cellar/gdb/8.2/lib/debug (relocatable)

("Relocatable" means the directory can be moved with the GDB installation tree, and GDB will still find it.)

看来我的GDB确实是64位,所以我猜这不是问题所在。我还找到了this post,其中最佳答案表明gdb 8.2不可能被破坏,我应该降级到8.0.1。然而,编辑说GNU团队的更新已经(据说)修复了问题所以我运行:

brew update

并确保一切都是最新的,但我仍然得到相同的错误。

我在这里结束了,我已经花了太多时间试图解决这个问题。如果它无法修复,你能建议其他无障碍的方法(大量强调无忧无虑)我可以在我的Mac上调试C / C ++程序吗?否则,我会坚持到我大学的计算机实验室。

编辑:这是我从终端编译的方式

g++ -g main.cpp -o main

我正在使用g ++编译器在Netbeans中使用C ++ 14标准编译调试模式(64位)。

我通过写入终端编译后调用gdb:

gdb main

或者只是在Netbeans中使用GUI

c++ macos debugging gdb netbeans-8
1个回答
0
投票

macOS上的编译器令人困惑。 Apple提供LLVM编译器作为Xcode的一部分,但它在/usr/bin/g++提供了一个存根,使人们相信他们正在使用GCC,即GNU编译器集合。然后他们尝试使用gdb,即GNU调试器和LLVM生成的可执行文件,并发现它不起作用。

恕我直言,你需要使用Apple提供的全部工具,或者完全使用GNU提供的工具。


那么,让我们看看第一个选项 - 使用Apple工具。在这种情况下,您编译:

/usr/bin/g++ -g main.cpp -o main

和调试:

/usr/bin/lldb ./main

并且调试器命令看起来与GDB非常相似。


第二种选择是使用通常使用自制软件最好安装的GCC和GDB。安装命令是:

brew install gcc
brew install gdb

然后你将编译类似于:

/usr/local/bin/g++-8 -g main.cpp -o main

并调试类似于:

/usr/local/bin/gdb ./main

但是,我暂时无法让它在macOS Mojave上工作!我读了here,GDB v8.1在macOS上不起作用,你需要安装v8.0.1,但似乎不能用自制软件做。

© www.soinside.com 2019 - 2024. All rights reserved.