如何通过GCC创建临时文件排查 [英] how to troubleshoot through gcc temporary file creation

查看:329
本文介绍了如何通过GCC创建临时文件排查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编写C(不是C ++)code,我在链接时收到错误,某些标识已经在多个地方被定义,但如下图所示,输出很神秘。

While compiling C (not c++) code, I am getting error during link time, that certain identifiers have been defined at multiple places, but as shown below, the output is very cryptic.

有没有办法摆脱的gcc更好的消息,这样我可以看到哪些文件的多个定义的原因是什么?

Is there a way to get better messages from gcc, so that I can see which files are the cause of multiple definitions?

/tmp/cc8kgsLE.o:(.rodata+0x0): multiple definition of `PR_SZ'
/tmp/ccDfv6U4.o:(.rodata+0x0): first defined here
/tmp/cc8kgsLE.o:(.rodata+0x8): multiple definition of `PR_SEC_SZ'
/tmp/ccDfv6U4.o:(.rodata+0x8): first defined here
/tmp/cc8kgsLE.o:(.rodata+0x10): multiple definition of `PR_NSEC_SZ'
/tmp/ccDfv6U4.o:(.rodata+0x10): first defined here

collect2: ld returned 1 exit status

更新:根据答复,我进一步指出,澄清
PR_SZ PR_SEC_SZ PR_NSEC_SZ 在一个<$定义C $ C> .H 文件,该文件是由的#ifndef 的#define 和 #ENDIF 宏..

UPDATE: Based on responses, i clarify further that PR_SZ, PR_SEC_SZ, PR_NSEC_SZ are defined in ONE .h file, which is protected by #ifndef, #define and #endif macros..

在编制方面,我只需键入:

In terms of compiling, i simply type:

gcc -Wall -I. -file1.c file2.c -o file2

更新:

除了响应,我发现下面的链接相关
全局常量不使用#define

In addition to responses, i found the below link relevant global constants without using #define

推荐答案

显示看起来并不神秘,我的输出,这是很清楚的......
在全局变量(这是不好的) PR_SZ,PR_SEC_SZ,PR_NSEC_SZ 被定义为多个.c文件

The output displayed doesn't look cryptic for me, it's very clear... The globals variables (this is bad) PR_SZ, PR_SEC_SZ, PR_NSEC_SZ are defined into more than one .c files

你如何编译你的项目?

下面的主要问题,那就是的.o 文件名不匹配.c文件的文件名。
因此,为了能看到一个更好的消息,你应该提高你的Makefile或任何你正在使用生成项目。

Here the main problem, it's that .o filename doesn't match the filename of the .c file. So to be able to see a better message you should improve your Makefile or whatever you are using to build your project.

有关信息:


  • .H 全局变量的原型声明必须由关键字pfixed $ P $ 的extern

  • 在只有一个 .C 文件中的变量应能正常申报

  • In .h the prototype of global variables declarations must be prefixed by the keyword : extern
  • In only one .c file the variable should be declare normally

这篇关于如何通过GCC创建临时文件排查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆