2016-06-21 249 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,然后做一次类似以下。

菜单>产品>清洁 ...然后运行该项目

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

相关问题