【问题标题】:Producing a.out with makefile and disable warning messages使用 makefile 生成 a.out 并禁用警告消息
【发布时间】:2017-08-18 22:42:31
【问题描述】:

这里有两个独立的问题。

首先,是否可以修改 makefile 以生成 GDB 可读的 a.out?其次,在makefile中,如何禁用屏幕输出的所有警告信息?

这是makefile的内容:

ALL: timefield eqloc3d getdat

timefield: timefield.c common.c common.h getpar.c time_3d.c modresample.c eq.c eq.h
    cc timefield.c common.c getpar.c time_3d.c modresample.c eq.c ./libgeo.a -lsunmath -lm -g -o timefield

eqloc3d: deri.c eqloc3d.c getpar.c main.c  modresample.c common.h common.c modifyxy.c modifyxyz.c eqloc3d.h eq.c eq.h model.h initeqloc.h initeqloc.c
    cc deri.c eqloc3d.c getpar.c main.c modresample.c common.c modifyxy.c modifyxyz.c eq.c initeqloc.c ./libgeo.a -lsunmath -lm -xlic_lib=sunperf -g -o eqloc3d

getdat: eq.c eq.h getdat.c
    cc -g eq.c getdat.c -o getdat libgeo.a -lm

如果我运行 makefile,它会创建三个二进制可执行文件:timefield、eqloc3d、getdat。一旦程序没有产生正确的输出,我就没有 a.out 以便我可以使用 GDB 来跟踪异常。

【问题讨论】:

  • 您想知道如何抑制来自编译器的警告消息,以及如何启用调试器。想一想。

标签: makefile gdb cc


【解决方案1】:

为什么需要 a.out?

根据您的 makefile,您的 makefile 会生成 3 个可执行文件。他们正在生成.....

第一个问题:

是的。您必须添加“-g”,以使可执行文件可调试。 在您发布的 makefile 中,所有三个可执行文件 getdattimefieldeqloc3d 都已使用“-g”构建。

因此可执行文件已准备好进行调试。只需如下所示调用即可。

$ gdb getdat 

$ gdb timefield

$ gdb eqloc3d

然后设置断点并使用适当的参数调用run(如果有)。

第二个问题:

使用-w 禁止所有警告消息。

例如:

cc -w -g eq.c getdat.c -o getdat libgeo.a -lm

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-26
    • 2012-10-07
    • 1970-01-01
    • 1970-01-01
    • 2012-10-06
    • 1970-01-01
    • 1970-01-01
    • 2014-12-15
    相关资源
    最近更新 更多