通过预处理、编译、汇编和链接进行调试
有时,当gcc输出错误时,我们会通过-E、-S、-c等选项来分解预处理、编译、汇编、链接各个阶段的过程。这是示例。
我只是想知道这四个阶段中的每一个阶段都可能发生什么类型的错误,如果其中一个阶段发生了一个错误,而之前的阶段没有发生,这将如何指导您找到错误的原因并纠正它?
Sometimes when there are errors output by gcc, one will break down the the process for each stage of preprocessing, compilation, assembly, linking by options like -E, -S and -c. Here is an example.
I just wonder what types of errors could happen at each of these four stages and if there is one error occuring at one of these stages but not at previous stages, how will this guide you to locate the reason of the error and correct it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我清楚地记得每个术语的含义:
预处理错误:“abcdefg”不是有效的关键字,因此预处理将失败:
编译错误:“fight!now”不是有效的标识符,因此编译将失败:
链接错误:“myfunc”由从未定义过声明:
你看,知道工具链检测到错误的位置有助于了解可能是什么类型的错误。但通常工具链发出的消息足以了解错误所在的位置。当然,它需要习惯于将参数传递为 -Wall 甚至 -Wextra 以获得更多有关可能出现问题的警告。
If I remember well the meaning of each term:
Preprocessing error: `abcdefg' is not a valid keyword so preprocessing will fail:
Compilation error: `fight!now' is not a valid identifier so compilation will fail:
Linking error: `myfunc' is declared by never defined:
You see, knowing where the tool chain detects the error helps knowing what kind of error it could be. But often the messages the tool chain emits is enough to understand where the error resides. Of course it requires being used to passing parameters as -Wall or even -Wextra to get more warnings about what could be wrong.