Tom
Tom

Reputation: 45

Why am I getting this particular Mach-O linker problem?

I’ve looked at all the Mach-0 Linker questions on SO but can’t find any that seem specific to my problem. My app was compiling without issues for weeks in the debugger and this seemed to come out of the blue. Problem seems to be pointing to two source files (keypad.o and setoutput.o). Previous Mach-O errors have usually told me that so-and-so can’t be referenced from ‘some file’.o, but no such easy clues in this case. Error shown below:

ld "/Users/Administrator/Library/Developer/Xcode/DerivedData/MacOS_Cover-aemdqkcjvuomtjfhkycsyowsgisn/Build/Products/Debug/MacOS Cover.app/Contents/MacOS/MacOS Cover" normal x86_64
cd "/Users/Administrator/Desktop/MacOS Cover"
setenv MACOSX_DEPLOYMENT_TARGET 10.6
/Developer/usr/bin/clang -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -L/Users Administrator/Library/Developer/Xcode/DerivedData/MacOS_Cover-aemdqkcjvuomtjfhkycsyowsgisn/Build/Products/Debug -F/Users/Administrator/Library/Developer/Xcode/DerivedData/MacOS_Cover-aemdqkcjvuomtjfhkycsyowsgisn/Build/Products/Debug -filelist "/Users/Administrator/Library/Developer/Xcode/DerivedData/MacOS_Cover-aemdqkcjvuomtjfhkycsyowsgisn/Build/Intermediates/MacOS Cover.build/Debug/MacOS Cover.build/Objects-normal/x86_64/MacOS Cover.LinkFileList" -mmacosx-version-min=10.6 -framework Cocoa -o "/Users/Administrator/Library/Developer/Xcode/DerivedData/MacOS_Cover-aemdqkcjvuomtjfhkycsyowsgisn/Build/Products/Debug/MacOS Cover.app/Contents/MacOS/MacOS Cover"

ld: duplicate symbol _required in /Users/Administrator/Library/Developer/Xcode/DerivedData/MacOS_Cover-aemdqkcjvuomtjfhkycsyowsgisn/Build/Intermediates/MacOS Cover.build/Debug/MacOS Cover.build/Objects-normal/x86_64/keypad.o and /Users/Administrator/Library/Developer/Xcode/DerivedData/MacOS_Cover-aemdqkcjvuomtjfhkycsyowsgisn/Build/Intermediates/MacOS Cover.build/Debug/MacOS Cover.build/Objects-normal/x86_64/setoutput.o for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Command /Developer/usr/bin/clang failed with exit code 1

I’ve tried throwing away all the derived data files etc (which seem to spring right back a second later). I’d appreciate if anyone could help me resolve this please.

Upvotes: 0

Views: 50

Answers (1)

Ken Thomases
Ken Thomases

Reputation: 90551

Those two object files are each exporting a symbol with the same name (required; the underscore is an artifact of the compiler). Depending on exactly what you intend for those two, you might need to: a) rename one or both; or b) make one or both have internal linkage, usually by marking them static.

There's a good chance you think there's just one such symbol because you declared it in a header that both source files include. But, you may have unintentionally defined the symbol in the header, rather than just declaring it. Then, it's defined in every source file that includes it. You would have to show your source code with the declaration/definition of required and how it's brought into each source file.

Upvotes: 1

Related Questions