0

When i build my project I get a duplicate symbol error from clang.

    duplicate symbol _server in:
    /Users/ashwinjeyakumar/Library/Developer/Xcode/DerivedData/Hikes-emzsxfmokzerjhevoirupbsrobpm/Build/Intermediates/Hikes.build/Release-iphonesimulator/Hikes.build/Objects-normal/i386/HikeViewController.o
    /Users/ashwinjeyakumar/Library/Developer/Xcode/DerivedData/Hikes-emzsxfmokzerjhevoirupbsrobpm/Build/Intermediates/Hikes.build/Release-iphonesimulator/Hikes.build/Objects-normal/i386/HikeSearchResultsViewController.o
ld: 1 duplicate symbol for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

To debug this, I found where I defined server (it was a property) and removed it, replacing it with an info.plist entry. The error wouldn't go away though. I've tried:

  • renaming the Server entry in Info.Plist
  • 'rm -rf' under /Users/[myusername]/Library/Developer/Xcode/DerivedData

A Shift+cmd+F search of my xcode project doesnt find any results for 'server' but the error still persists.

theraju
  • 461
  • 4
  • 13

1 Answers1

0

I had an import "Constants.h" in my project. Constants.h had the following:

#ifndef Hikes_Constants_h
#define Hikes_Constants_h

#define kBgQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
NSString *server = @"http://192.168.56.101:3000/";

#endif

The catch was that Constants.h was no longer in my XCode project, so searches for the symbol never gave results. I finally noticed i was importing a header that wasn't in the project.

theraju
  • 461
  • 4
  • 13
  • As an aside, this pattern will generally give you the duplicate symbol problem if you include `Constants.h` in more than one .m file. The `#ifndef` statement is only effective once per .m file, so `Contants.h` (and notably your `server` definition) will be compiled twice, and you'll have duplicate symbols. You .h should use the `extern` construct. See http://stackoverflow.com/questions/538996/constants-in-objective-c. BTW, `FOUNDATION_EXPORT` is, effectively, just `extern`. – Rob Dec 08 '12 at 08:06