Sublime C++ Mac

Mac

I had a bit of an journey yesterday getting gdb, (an interactive debugger for gcc) compiling and working in Sublime Text 3 (via the SublimeGDB package), so I thought I should document the issues I ran into & what finally worked, for others and perhaps my future self.

Mac Sublime C++

Sep 09, 2019 On macOS terminal ctrl+C terminates the program running. In Sublime Text, cmd+B runs a program such as Python, Ruby or such. If I want to terminate a running code, what is the shortcut key in Subl. C environment which builds using CMake and uses the clangd language server for extra IDE features. Using Sublime Text 4. For intermediate to advanced users.

When I first installed the SublimeGDB package and tried to run it, nothing seemed to happen, so I went to View -> Show Console and saw a the directory is invalid error. I googled a bit and ended up following the instructions here to get it to work: instead of setting the workingdir to ${folder:${file}} or ${folder:${project_path:your_executable_name}}, as the default settings seem to suggest -- or even ~/..., I ended up using an absolute path ('/Users/my-user-name/...) and specifying these other settings in my *.sublime-project file:

Sublime C++ Compiler

Sublime C++ Mac

Then I got an error about it not being able to find gdb (command not found, I think), which indicated the gdb wasn't installed on my system. I tried installing it via Homebrew (brew install gdb), which appeared to work, but when I tried to use it, it failed with this error:

This *.dylib library wasn't on my machine; I'm guessing (and this is just speculation; I don't actually know how Homebrew works) that Homebrew installed a pre-compiled version of gdb which depended on a library that existed on the machine it was compiled with, but did not exist on my machine.

I was able to address this by compiling gdb myself -- first, I downloaded & tried to compile the latest version (8.1) from http://ftp.gnu.org/gnu/gdb/. There were 150 warnings and 1 error, which was buried in the warnings & I couldn't find by searching the console because the warnings had the word 'error' in them too. Then I downloaded & compiled the previous version (7.12), via running ./configure and make and, in spite of a ton of warnings, it compiled! I installed it (I think via sudo make install) and then followed the instructions here to generate a CodeSigning certificate on macOS, to configure the OS to always trust the cert and to sign the newly-installed gdb executable with the cert.

More Images For Sublime C Mac ยป

So, after over an hour of wrestling, I was finally able to run the gdb debugger from Sublime. It ran to the breakpoint and then I was able to use the step and next commands to walk through the code. It took about 60 seconds to find & fix the bug in my game (a clone of the classic action/block-pushing game, Beast).