27
votes

I am using c++/eclipse kepler on mac, and I cannot debug any project. The error is "Error while launching command: gdb --version" Besides that, I can build and run my code using other libraries.

I searched a site that is similar to my problem: Debugger for C++ eclipse gives the following error. 'Launching program name' has encountered a ... Error while launching command: gdb --version

But what should I change if I am using a mac?

6
Do you actually have gdb installed? Run gdb --version within your terminal. - Till
In my experience this is eclipse bug related to system PATH. Check if it's valid or if you can simplify it. - dbrank0
Yes, I have gdb, instead it changes its name to ggdb, but I still cannot debug - user3000888
Are you on OS X Mavericks? Also, how do you know it's changing the name? What do you mean by that? - Neil Traft

6 Answers

21
votes

You can fix this by specifying the full path to gdb. You can do this separately for each debug configuration, and you can also set the default gdb location in the preferences under C/C++ > GDB. For example, if you installed gdb via Homebrew, then it's probably located under /usr/local/bin:

GDB Debug Configuration

And here's a screenshot of the Preferences:

GDB Preference

I still don't know why Eclipse can't find GDB even though it is on my path. I guess it doesn't use my .bash_profile or my .bashrc? You could try symlinking gdb into /usr/bin. Maybe Eclipse will look there.

Edit: I tried the symbolic link idea and now Eclipse can debug, but it crashes inexplicably while doing so! So, I guess... don't do that?

12
votes

This guide from a UC Irvine Computer Science professor's page is a very well-written, detailed, and Mac-specfic description of all the steps involved in installing GDB, creating a certificate, signing GDB using that certificate, and finally configuring Eclipse. I was found this very helpful as someone unfamiliar with each of these steps.

GDB Installation on Mac OS X

8
votes

I had the same problem. I solved it by:

  1. Install a gdb - ( I used 7.8.1) - compile and install it. It got installed in usr/local/bin
  2. Codesigning certificate
  3. Open eclipse executable using sudo. Otherwise I still get the error.

I am on OS X. Hope this helps.

1
votes

I had this error too now, and spent more than an hour looking for it. In my case, the path was correct, and eclipse seemed to fail to start "any" executable as debugger. (I tested with gksudo cat, but it clearly never got to effectively running it).

The final reason was that I had put in my eclipse.ini -Xms1G and -Xmx1G. It seemed to already use the full memory for the indexer, and trying to allocate some more memory to start the debugger failed with an "unkown" error. Removing the memory limitations fixed the issue.

Hope this helps someone

0
votes

I had many difficulties making GDB to work on Eclipse. I tried LLDB instead and it worked like a charm:

https://wiki.eclipse.org/CDT/User/FAQ#How_do_I_get_the_LLDB_debugger.3F

This can be a more convenient alternative for Mac users.

0
votes

Mac OS Sierra 10.13.6 gdb 8.0.1

had the same error as topic-starter.

first, I set the path as Neil Traft (here in the answers) explains to usr/local/bin/gdb;

But it didn't work.

I found these instructions: https://gist.github.com/gravitylow/fb595186ce6068537a6e9da6d8b5b96d

and I discovered that I already had gdbcert1 in my System. So I followed everything from 7. Works!