59

I'm getting an error message from the linker when building a Swift program with Xcode 6 beta 6, targeting iOS 8. This code compiled and ran correctly with beta 5.

Undefined symbol for architecture x86_64:
__TFSs26_forceBridgeFromObjectiveCU__FTPSs9AnyObject_MQ__Q_", referenced from:
 __TFC8RayTrace14RayTracingPlot15drawFocalPointfS0_FT_T_ in RayTracingPlot.o
ld: symbol(s) not found for architecture x86_64

Here's the code in question:

private func drawFocalPoint() {
    var attributes = Dictionary<String, AnyObject>()

    let FString: String = "F"
    let distance: CGFloat = focalDistance

    let centerX = CGRectGetMidX(bounds)
    let centerY = CGRectGetMidY(bounds)

    let circleRadius: CGFloat = 4.0
    let focalPointFrame = CGRectMake(0, 0, circleRadius * 2.0, circleRadius * 2.0)
    var path = UIBezierPath(ovalInRect: focalPointFrame)
    let color = UIColor.blackColor()

    let currentContext = UIGraphicsGetCurrentContext()
    CGContextSaveGState(currentContext)
    let shadowColor = UIColor(white:0, alpha:0.75).CGColor
    CGContextSetShadowWithColor(currentContext, CGSizeMake(0, 4), CGFloat(8), shadowColor)

    // Image F
    var imageFPath = UIBezierPath(CGPath: path.CGPath)
    let imageFTransform = CGAffineTransformMakeTranslation((centerX - distance - circleRadius),
        (centerY - circleRadius))
    imageFPath.applyTransform(imageFTransform)
    color.set()
    imageFPath.fill()
    FString.drawAtPoint(CGPointMake(centerX - distance - circleRadius, centerY + 5), withAttributes:attributes)

    CGContextSetShadowWithColor(currentContext, CGSizeMake(0.0, 0.0), CGFloat(0.0), nil) // Clear shadow
    CGContextRestoreGState(currentContext)
}

I'd appreciate a hint about where in this code to look for the error so I can fix it. Thank you.

DrScott
  • 633
  • 1
  • 6
  • 7

3 Answers3

119

I got this error even with the new version of Beta6 that was release hours after the bad one got pulled.

I've solved this and other similarly illegible errors by deleting the contents of the Derived folder. You can find where that folder is located by going to Preferences > Locations.

The default path is: /Users/[your username]/Library/Developer/Xcode/DerivedData

You can also hold Option while the Product menu is open in Xcode, which will change Clean to Clean Build Folder... and accomplish the same task without having to folder-hunt.

iwasrobbed
  • 46,496
  • 21
  • 150
  • 195
Paul Ardeleanu
  • 6,620
  • 2
  • 40
  • 41
  • 2
    alright. Deleting the build directory did it. Couldn't just Cmd+K to clean it. Had to manually delete it. – Patrick Bassut Aug 20 '14 at 22:36
  • 18
    You can also hold `Option` while the `Product` menu is open in Xcode, which will change `Clean` to `Clean Build Folder...` and accomplish the same task without having to folder-hunt. – Craig Otis Aug 22 '14 at 00:54
  • 2
    You can also just use the "Delete" button in the Derived Data section of the project in the Organizer (`Window->Organizer->Projects->->Derived Data`) – Matt Gibson Aug 24 '14 at 09:49
7

Another cause of this error (seen with Xcode 6.1.1, and Xcode 6.2 Beta 3), is having an enum with only one case in one class, and declaring a variable of that type in a second class.

This code will cause a linker error:

class ClassA {
    enum ExampleEnum {
        case Option1
    }
}

class ClassB {
    var example: ClassA.ExampleEnum = .Option1
}

This will fix it.

class ClassA {
    enum ExampleEnum {
        case Option1
        case Option2 // Added a second case
    }
}

class ClassB {
    var example: ClassA.ExampleEnum = .Option1
}

Radar for more info and a sample project: http://openradar.appspot.com/19369147

An enum with only one case is pretty useless in practice and so the compiler is probably optimizing it away or something. I hit this when setting up a new project, using an enum for achievements to be determined later, and had just 1 placeholder.

Also note: Use Watchdog http://watchdogforxcode.com/ to avoid having to worry about Derived Data issues.

Dave Wood
  • 13,143
  • 2
  • 59
  • 67
  • 1
    Unbelievable. This was absolutely my problem. I wish I could give you multiple upvotes because of how hosed I would have been without this answer. – thedayturns Mar 26 '15 at 19:25
  • 1
    I'm so glad this answer caught the corner of my eye. This was my problem. Truly unbelievable. Thanks for posting this! – rainypixels Mar 28 '15 at 04:13
1

For other people that might stumble on this error. I have had this when implementing CocoaPods and not setting my target's Other Linker Flags to $(inherited)

Roland Keesom
  • 8,180
  • 5
  • 45
  • 52