it's my first post so I apologise in advance if I post anything wrong or incorrectly format.
My system: MacBook Pro running MacOS Mojave 10.14.1, Netbeans 8.2
I'm running a simple C++ program that prints hello world:
int main(int argc, char** argv) {
cout << "Hello World" << endl;
return 0;
}
So my issue is that I cannot run the debugger on my MacBook using Netbeans or Terminal commands. Every time I do, I get the following error:
not in executable format: file format not recognized
I originally had the problem where I had a missing debugger command. I followed the directions here and installed Homebrew, got gdb, and code-signed the gdb binary. After all that I started getting the error highlighted above.
I google this new problem, and I find this stack overflow post which suggests that I might be running a 32-bit gdb while building in 64-bit. However, based on the output when running 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
And the configuration of the 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.)
It seems that my GDB is indeed 64-bit so I'm guessing that's not the problem. I also found this post where the top answer suggests that gdb 8.2 is impossibly broken and I should just downgrade to 8.0.1. However, an edit says that an update by the GNU team has (supposedly) fixed the problem so I run:
brew update
and ensure that everything is up-to-date, but I still get the same error.
I'm at my wits end here, and I've put in WAY too much time into trying to resolve this issue. If it can't be fixed, can you suggest other hassle-free ways (massive emphasis on hassle-free) I can debug C/C++ programs on my Mac? Otherwise, I'll stick to my university's computer labs.
EDIT: here's how I compiled from the terminal
g++ -g main.cpp -o main
I'm compiling in Debug mode (64-bit) in Netbeans with C++14 standard using the g++ compiler.
I call gdb after compiling by writing to the terminal:
gdb main
or by simply using the GUI in Netbeans