Sean Allred
Sean Allred

Reputation: 3658

GCC complaining about a duplicate definition (where only one exists)

I just seem to hit one error after another when dealing with larger projects in Xcode. This time, GCC is complaining of a duplicate definition for a struct-printing function - one where it is actually defined (in a different file), and one where it is used (in the driver).

The specific error I'm getting is this:

ld: duplicate symbol _fprintConfiguration in
/.../bits.build/Objects-normal/x86_64/Block.o and
/.../bits.build/Objects-normal/x86_64/bits.o

where Block.o contains the definition and bits.o contains the driver.


I've done some research on this already, but it seems that every problem exists with people actually defining it twice by virtue of #include, but in all my files I only use #import. Isn't the #import directive supposed to 'intelligently' include files? Are there any other reasons I could be getting this error? Are there any other solutions I can try?

Thanks for your help :)

Upvotes: 1

Views: 449

Answers (2)

Norman Bo Graham
Norman Bo Graham

Reputation: 1

Use -save-temps, and then look at the ii file for the file in question. Search for the duplicated structure in the file. The ii file, is the list file. It will show the duplicates.

Upvotes: 0

Jesse Beder
Jesse Beder

Reputation: 34064

The problem is that you're including the same definition in multiple translation units (both Block.o and bits.o). To fix this, declare the function inline or move the definition to a (single) source (non-header) file.

This is orthogonal to the question of #include vs. #import. That's about including the same code multiple times in the same translation unit.

Upvotes: 3

Related Questions