C语言 如何使用 GCC 在 mac 终端上调试 C 程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19458449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can i debug a C program on mac Terminal with GCC?
提问by robotik
i want to debug the c Program, on my MAC Terminal, i use "gcc -o deng.c" p.s the Path is right,but it says "No such file or directory". i have install xcode and Commd line already.
我想在我的 MAC 终端上调试 c 程序,我使用“gcc -o deng.c” ps 路径是正确的,但它说“没有这样的文件或目录”。我已经安装了 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;
}
回答by liqimai
You need to use lldb, the substitute of gdb on Mac,
你需要使用lldb,Mac上gdb的替代品,
gcc -g deng.c -o deng
lldb ./deng
回答by SheetJS
-ospecifies the output file. That's not what you want here. You probably meant to run
-o指定输出文件。这不是你想要的。你可能想跑
gcc -g deng.c
The -gtells the compiler to include debugging symbols. The binary is called a.out(and you can change the program name to dengby running gcc -g deng.c -o deng)
该-g告诉编译器包括调试符号。调用二进制文件a.out(您可以deng通过运行将程序名称更改为gcc -g deng.c -o deng)
To actually run the program, you have to run ./a.out(or ./deng, if you ran gcc with -o deng).
要实际运行该程序,您必须运行./a.out(或者./deng,如果您使用 -o deng 运行 gcc)。
To debug the program, you run gdb a.out(or gdb deng) and then type run. For more help on gdb, read the documentation
要调试程序,请运行gdb a.out(或gdb deng),然后键入run。有关 gdb 的更多帮助,请阅读文档

