0

There are similar questions, but none that answer my question.

I am using Swift 2.0 I am working on a project that shows longitude and latitude using CoreLocation.

I also am using the Social framework to post to twitter and facebook.

I am getting an error that says "error: linker command failed with exit code 1 " and then it tells me "(use -v to see invocation)" but I do not understand that.

I am going off an answer here on SO to write the location services portion. here is the link https://stackoverflow.com/a/24696878/6140339

here is my code:

import UIKit
import Social
import CoreLocation

@UIApplicationMain

class FirstViewController: UIViewController, CLLocationManagerDelegate, UIApplicationDelegate {


var window: UIWindow?
var locationManager: CLLocationManager!
var seenError : Bool = false
var locationFixAchieved: Bool = false
var locationStatus : NSString = "Not Started"

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
    initLocationManager();
    return true
}

func initLocationManager() {
    seenError = false
    locationFixAchieved = false
    locationManager = CLLocationManager()
    locationManager.delegate = self
    CLLocationManager.locationServicesEnabled()
    locationManager.desiredAccuracy = kCLLocationAccuracyBest

    locationManager.requestAlwaysAuthorization()
}

func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
    locationManager.stopUpdatingLocation()
    if (error == true) {
        if (seenError == false) {
            seenError = true
            print(error)
        }
    }
}

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    if (locationFixAchieved == false) {
        locationFixAchieved = true
        let locationArray = locations as NSArray
        let locationObj = locationArray.lastObject as! CLLocation
        let coord = locationObj.coordinate

        print(coord.latitude)
        print(coord.longitude)
    }
}

func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
    var shouldIAllow = false

    switch status {
    case CLAuthorizationStatus.Restricted:
        locationStatus = "Restricted Access to location"
    case CLAuthorizationStatus.Denied:
        locationStatus = "User denied access to location"
    case CLAuthorizationStatus.NotDetermined:
        locationStatus = "Status not determined"
    default:
        locationStatus = "Allowed to location Access"
        shouldIAllow = true
    }
    NSNotificationCenter.defaultCenter().postNotificationName("LabelHasBeenUpdated", object: nil)
    if (shouldIAllow == true) {
        NSLog("Location to Allowed")
        //Start location services
        locationManager.startUpdatingLocation()
    } else {
        NSLog("Denied access: \(locationStatus)")
    }
}



@IBAction func postToFacebookButton(sender: UIButton) {
    if(SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook)){
        let socialController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
        //creates post with pre-desired text
        socialController.setInitialText("")

        self.presentViewController(socialController, animated: true, completion: nil)
    }
}


@IBAction func postTweetButton(sender: UIButton) {
    if(SLComposeViewController.isAvailableForServiceType(SLServiceTypeTwitter)){
        let socialController = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
        //creates post with pre-desired text
        socialController.setInitialText("")

        self.presentViewController(socialController, animated: true, completion: nil)
    }
}

override func preferredStatusBarStyle() -> UIStatusBarStyle {
    return .LightContent
}

override func viewDidLoad() {
    super.viewDidLoad()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

//layer.cornerRadius layer.cornerRadius

}

Entire error message:

duplicate symbol _main in: /Users/user/Library/Developer/Xcode/DerivedData/FarOut-ekrxzlgzfahpruavmlhyhiwiynum/Build/Intermediates/FarOut.build/Debug-iphonesimulator/FarOut.build/Objects-normal/x86_64/AppDelegate.o /Users/user/Library/Developer/Xcode/DerivedData/FarOut-ekrxzlgzfahpruavmlhyhiwiynum/Build/Intermediates/FarOut.build/Debug-iphonesimulator/FarOut.build/Objects-normal/x86_64/FirstViewController.o ld: 1 duplicate symbol for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

Community
  • 1
  • 1
humans
  • 549
  • 8
  • 18
  • You can see the linker output if you select the last icon in the project navigator (speech bubble) and then expand your "build" log. Look for the red linker error and click to expand that text; it should show why the linker was unable to complete – Paulw11 Jun 21 '16 at 01:27

2 Answers2

1

Your code works well in my Xcode. I think after deleting Derived data, cleaning and rebuilding will works fine. One more thing, you need to split code of AppDelegate and ViewController cause they have their own roles.

Paul
  • 759
  • 2
  • 7
  • 20
  • I cleaned, rebuilt, and didn't work. I restarted xCode, didn't work. Did you just copy paste? I am not sure whats not working. From what i can tell it has nothing to do with my social code, it has to do with my location code, i copied and pasted it into a new project and still recieved the same error – humans Jun 21 '16 at 00:38
  • @GabrielMSC I created new project of Single View Application. and then deleted two file, (AppDelegate.swift, ViewController.swift). then created FirstViewController.swift and copy paste. Could you copy paste the whole error displayed? There are extra information above error comment. – Paul Jun 21 '16 at 01:19
  • 1
    @GabrielMSC The error says you have a duplicate symbol, `@UIApplicationMain` annotation. You have two choices, delete AppDelegate.swift file or move your app delegate code from FirstViewController to AppDelegate. I suggest later one, I mentioned before, AppDelegate has its own roles. Also mixing it is not recommended by Apple's guideline. – Paul Jun 21 '16 at 01:32
0

So many different problems for the same error message.(Linker command failed with exit code 1)

1) if you had two same constants in different classes then also this issue happens.

2) if you have accidently imported a .m file instead of .h file in an implementation file.

3) This error can also be occurred if you have imported two different versions of same library ,in this case just remove the older version and keep only one version.

4) Adding the "other linker flags" in "Project" and not in "Targets". So, you move it to "Targets", it shouldn't be in "Project".

5) Check it out in project->target->build settings-> search enable bitcode->set NO in DEBUG

check out this .. if it's OK then once do like following.

Menu > Product > Clean ... then Run the project

Hope it helps you.. :)

Suraj Sukale
  • 1,778
  • 1
  • 12
  • 19