2016-06-21 62 views
0

也有類似的問題,但沒有回答我的問題。Swift:錯誤:鏈接器命令失敗,退出代碼爲1

我正在使用Swift 2.0我正在使用CoreLocation顯示經度和緯度的項目。

我也在使用Social框架發佈到twitter和facebook。

我得到一個錯誤,說「錯誤:鏈接器命令失敗,退出代碼1」,然後它告訴我「(使用-v看到調用)」,但我不明白這一點。

我在這裏寫下位置服務部分的答案。這裏是鏈接https://stackoverflow.com/a/24696878/6140339

這裏是我的代碼:

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 

}

整個錯誤消息:

在_main重複的符號: /用戶/用戶/庫/開發/的Xcode /DerivedData/FarOut-ekrxzlgzfahpruavmlhyhiwiynum/Build/Intermediates/FarOut.build/Debug-iphonesimulator/FarOut.build/Objects-normal/x86_64/AppDelegate.o /Users/user/Library/Developer/Xcode/DerivedData/F arOut-ekrxzlgzfahpruavmlhyhiwiynum/Build/Intermediates/FarOut.build/Debug-iphonesimulator/FarOut.build/Objects-normal/x86_64/FirstViewController.o ld:1架構x86_64的重複符號 clang:error:linker命令失敗,退出代碼1 (使用-v來查看調用)

+0

你可以看到連接器輸出,如果你選擇在Project Navigator的最後一個圖標(講話泡泡),然後展開你的「構建」日誌。查找紅色鏈接器錯誤,然後單擊以展開該文本;它應該顯示爲什麼鏈接程序無法完成 – Paulw11

回答

1

您的代碼在我的Xcode中運行良好。我想刪除派生數據後,清理和重建將正常工作。還有一件事,你需要分解AppDelegate和ViewController的代碼,因爲它們有自己的角色。

+0

我清理,重建,並沒有工作。我重新啓動xCode,沒有工作。你剛剛複製粘貼?我不確定什麼不起作用。從我可以告訴它與我的社交代碼無關,它與我的位置代碼有關,我將其複製並粘貼到一個新項目中,仍然收到相同的錯誤 – GabrielMSC

+0

@GabrielMSC我創建了單一視圖應用程序的新項目。然後刪除兩個文件,(AppDelegate.swift,ViewController.swift)。然後創建FirstViewController.swift並複製粘貼。你能複製粘貼顯示的整個錯誤嗎?上面有錯誤評論的額外信息。 – Paul

+0

編輯的問題包含完整的錯誤消息 – GabrielMSC

0

那麼多不同的問題,爲相同的錯誤消息。(Linker command failed with exit code 1

1)如果您有兩個same constants在不同的班級,然後也是這個問題發生。

2)如果您在執行文件中意外導入了.m file而不是.h file

3)如果您導入了同一個庫的兩個不同版本,在這種情況下只刪除舊版本並只保留一個版本,也會發生此錯誤。

4)添加在 「Project」 該 「other linker flags」,而不是在 「Targets」。所以,你把它移動到「Targets」,它不應該在「Project」。

5)檢查它在項目 - >靶>構建設置 - >搜索使能bitcode->設置DEBUG NO

退房這個..如果是OK,然後做一次類似以下。

菜單>產品>清潔 ...然後運行該項目

希望它可以幫助你.. :)

相關問題