【问题标题】:How can I debug a C program on Mac Terminal with GCC?如何使用 GCC 在 mac 终端上调试 C 程序?
【发布时间】:2013-10-27 19:34:58
【问题描述】:

我想调试 c 程序,在我的 MAC 终端上,我使用“gcc -o deng.c” p.s 路径是正确的,但它说“没有这样的文件或目录”。我已经安装了 xcode 和 Commd 行。

#include <stdio.h>
#include <string.h>
#define maxn 1000+10

int a[maxn];
int main()
{
    int i,j,n,k,first=1;
    memset (a,0,sizeof(a));
    scanf("%d%d",&n,&k);
    for(i=1;i<=k;i++)
        for ( j = 1; j <=n; j++)
            if(j%i==0)
                a[j]=!a[j];
    for(i=1;i<=n;i++)
        if(a[i])
        {
            if(first) first =0;
            else
                printf(" ");
            printf("%d",i);
        }
    printf("\n");
    return 0;
}

【问题讨论】:

  • gcc -o deng.c?再见源代码...

标签: c xcode macos gcc


【解决方案1】:

你需要使用lldb,Mac上gdb的替代品,

gcc -g deng.c -o deng
lldb ./deng

【讨论】:

    【解决方案2】:

    -o 指定输出文件。这不是你想要的。你可能打算跑

    gcc -g deng.c
    

    -g 告诉编译器包含调试符号。二进制文件名为a.out(您可以通过运行gcc -g deng.c -o deng将程序名称更改为deng

    要实际运行该程序,您必须运行./a.out(或./deng,如果您使用-o deng 运行gcc)。

    要调试程序,请运行gdb a.out(或gdb deng),然后键入run。有关 gdb 的更多帮助,read the documentation

    【讨论】:

    • 要运行它,您必须输入./deng./a.out。点和斜线很重要。
    猜你喜欢
    • 2015-11-27
    • 2014-12-12
    • 1970-01-01
    • 2014-07-21
    • 1970-01-01
    • 2012-06-11
    • 2013-12-18
    • 2020-07-31
    • 1970-01-01
    相关资源
    最近更新 更多