Reputation: 1925
I'm using gcc to generate assembly files from multiple c files. When I try to use gas to assemble the generated assembly files, it spits out this error because it finds the symbols defined in multiple files.
Error: symbol '.L???' is already defined
Looking at the documentation, .L prefixed files are supposed to be local symbol names so why is gas complaining when it finds the same symbol name in different files?
Upvotes: 0
Views: 456
Reputation: 6413
I don't know what procedure are you using when compiling those files, but I ran into similar problems when I tried to compile output listing improperly.
Let's say you've got two files, main.c
and foo.c
:
/* main.c */
#include <stdio.h>
int main() {
printf("Hello");
if(5==7);
else printf("Yes");
}
/* foo.c */
#include <stdio.h>
int foo() {
printf("Single!");
if(7==5);
else printf("Yes");
}
If you produce assembly listing for every file individually, you can see...
.file "main.c"
.def ___main; .scl 2; .type 32; .endef
.section .rdata,"dr"
LC0:
.ascii "Hello\0"
LC1:
.ascii "Yes\0"
.text
.globl _main
.def _main; .scl 2; .type 32; .endef
_main:
....
.file "foo.c"
.section .rdata,"dr"
LC0:
.ascii "Single!\0"
LC1:
.ascii "Yes\0"
.text
.globl _foo
.def _foo; .scl 2; .type 32; .endef
_foo:
....
...that string constants used in the C code are also numbered individually for each file (LC0
and LC1
are present in both files, but they don't have the same content).
Now, if you try to compile these listings together...
as main.s foo.s
you get your errors...
foo.s:3: Error: Symbol `LC0` is already defined
foo.s:5: Error: Symbol `LC1` is already defined
The solution is not only to produce listings for each file separately, but also to compile every listing into separate object file and then link them.
as main.s -o main.o
as foo.s -o foo.o
gcc main.o foo.o
Upvotes: 1