How can I convince Xcode to fix a duplicate character symbol error?

This is different from the usual confusion over duplicate symbolic errors ... :-)

I am working on some legacy Mac code in an Xcode project that has the same global “trace” defined in several different source files, for example:

  • File1.c: SInt32 trace
  • File2.c: Boolean trace;

etc. .. It is clear that the original author meant that they have a file-specific area, but simply ignored the prefix of any of these lines with "statics". This is fine, easy to fix.

But I’m shocked that the linker will not interfere with this! It seems to me that the Xcode linker (I believe gnu ld) emits only duplicate warnings or errors for functions that are associated with a code segment, but not global variables that are associated with a data segment. Instead, it quietly merges them, which causes errors.

So ... how do I convince Xcode to emit link errors for duplicate global variables? Or get this information in some other way that might be a regular part of my build?

+6
linker xcode ld macos
source share
1 answer

Well, I thought I answered my question ... :-)

I posted earlier:

So, if you use Xcode with LLVM GCC 4.2, go to the build settings dialog, find “LLVM GCC 4.2 - Code Generation” and check “No Common Blocks”. This allows the -fno-common compiler, and changes the generation of the object file so that ld suffocates and emits if you have two globals in different source files with the same name.

Unfortunately, this does not look like a solution to all instances. This seems to be normal if all global types are of the same type.

But the example in the question is taken directly from the code, where a variable with the name "trace" is defined as global in two different files with two different types. And this is not yet caught by the build system when I check this checkbox.

+2
source share

All Articles