V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
musray
V2EX  ›  问与答

请教MAC中用terminal调试c语言程序的方法

  •  
  •   musray · 2012-03-24 23:29:05 +08:00 · 11716 次点击
    这是一个创建于 4409 天前的主题,其中的信息可能已经有所发展或是发生改变。
    百度谷歌了一大圈,找到了一个基本思路:用记事本之类的程序写代码,比如hello world。然后在terminal里通过gcc来调试。

    但遇到了很多困惑,希望大家指点:
    我找到了一个smultron的程序,写了c语言代码,存放到了桌面上,叫hello.c
    问题1:在terminal中如何找到hello.c?
    问题2:如何能像在vc++6.0那样编译并在runtime里看到执行结果?

    先行谢过!
    11 条回复    1970-01-01 08:00:00 +08:00
    zhuzhuor
        1
    zhuzhuor  
       2012-03-24 23:37:09 +08:00 via iPad
    Google gdb
    guoxx_
        2
    guoxx_  
       2012-03-24 23:53:32 +08:00
    cd ~/Desktop/
    gcc hello.c -o hello

    调试的话就gdb hello
    break设置断点 run运行程序 print显示变量值

    再具体的楼主还是google吧
    66450146
        3
    66450146  
       2012-03-24 23:54:54 +08:00
    man gcc
    man gdb

    楼主可以在Linux社区里面找到更详尽的关于gcc和gdb的资料。。。
    musray
        4
    musray  
    OP
       2012-03-24 23:57:15 +08:00
    一并感谢各位~我再研究研究
    013231
        5
    013231  
       2012-03-24 23:59:03 +08:00
    1:
    cd ~/Desktop
    2:
    gcc hello.c
    ./a.out

    不过你还是找本Linux教材系统的学习一下吧.
    stcui
        6
    stcui  
       2012-03-25 00:25:22 +08:00
    cd ~/Desktop
    make hello
    stcui
        7
    stcui  
       2012-03-25 00:25:52 +08:00
    ./hello
    musray
        8
    musray  
    OP
       2012-03-25 13:25:56 +08:00
    @013231 执行gcc hello.c的时候,提示:“-bash:gcc:command not found”?
    是我的机器上没安装gcc么?我是10.7.3,在APP STORE安装了最新版XCODE。
    musray
        9
    musray  
    OP
       2012-03-25 13:27:36 +08:00
    @stcui 执行make hello的时候,提示-bash:make:conmmand not found。请问怎么回事儿?和上一楼的问题类似。
    clowwindy
        10
    clowwindy  
       2012-03-25 13:54:28 +08:00
    装 Xcode 的 Commandline Tools,编译链就有了

    如果你纠结于终端,这个大概就是你想要的……

    1. 学写 Makefile
    2. 学 emacs/vim
    3. 学 gdb
    4. 学 emacs/vim 里使用 gdb 的方法
    musray
        11
    musray  
    OP
       2012-03-25 15:44:19 +08:00
    @clowwindy 哈哈,安装了Command line Tools果然gcc和make都有了!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1242 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 17:50 · PVG 01:50 · LAX 10:50 · JFK 13:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.