303
303

Reputation: 1108

Linker error: How can there be a duplicate symbol in just one file?

From what I understand, a linker error due to a duplicate symbol means that:

  1. a symbol was defined in more than one source file
  2. resulting in the same symbol in two different object files after compilation
  3. so the linker does not know which of the two symbols he should link to.

While trying to compile a demo project from www.ugfx.io I came across this error:

duplicate symbol _main in:
    .build/obj/GFXLIB/demos/modules/gdisp/basics/main.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [.build/demotest.elf] Error 1

In contrast to every duplicate symbol error I could find on the web there is just one file listed as part of this error. And the source file belonging to this object file has just one main symbol. You can view it here.

How shall I even understand this error? And what could be its cause?

Upvotes: 1

Views: 2809

Answers (1)

ayehia
ayehia

Reputation: 85

It happened to me when I included the same source file twice in the compiling command, e.g. :

$gcc -o main main.c becool.c foo.c bar.c becool.c end.c

The repeated becool.c caused a duplicate symbol error.

So, if this is the problem, just review your compiling command and remove such duplicates

Upvotes: 2

Related Questions