Mac eclipse 编译、调试c++ 程序


可以先安装个CDT插件:  

  eclipse菜单 -> Help -> Install New Software... -> Work with (Add..)  

  Name:CDT  

  Location:http://download.eclipse.org/tools/cdt/releases/galileo

finish

 

build错误:

  launch failed, binary not found

解决方法:

  

debug错误:

  "Launching projectName" has encountered a problem. Error with command gdb --version 

  Error with command: gdb --versionCannot run program "gdb": Unknown reason

解决方法:

  1.安装brew

    详见:http://www.cnblogs.com/SZxiaochun/p/7674316.html

  2.使用brew安装GDB

    brew install gdb

  3.配置eclipse,进行debug。
    偏好设置->Preferences > C/C++ > Debug > GDB

  http://ntraft.com/wp-content/uploads/2014/01/eclipse-gdb-pref1.png

  如果你已经创建了一些工程,比如上面的测试程序,可以在 Run -> Debug Configurations进行修改

  

  eclipse-gdb-debug 

  4.创建证书 (前3步走完之后,调试不报错的话,就不需要这一步

    详见:http://www.cnblogs.com/SZxiaochun/p/7747989.html

    如果这一步走完,调试还报gdb认证错误的话。就删除 gdb ,再重新装一下,重新 codesign -s gdb-cert /usr/local/bin/gdb 一下就好了。(亲测)

    

如果gdb报错:gdb terminated with signal ?, unknown signal

解决方法:

  Create a .gdbinit file in your home-direcetory and write "set startup-with-shell off" in it.

  File can be created using vi ~/.gdbinit.

  然后修改下eclipse中 Debug Configuartions 的配置:

    

   重启eclipse就可以debug了。

效果:  

原文地址:https://www.cnblogs.com/SZxiaochun/p/7748152.html