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.
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
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
UPDATE:
In addition to responses, i found the below link relevant
global constants without using #define
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_SZare defined into more than one .c filesHow do you compile your project ?
Here the main problem, it’s that
.ofilename 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.
For information :
.hthe prototype of global variables declarations must be prefixed by the keyword :extern.cfile the variable should be declare normally