ios 链接器命令在 Swift 中失败,退出代码为 1(使用 -v 查看调用)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25525020/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 02:04:01  来源:igfitidea点击:

linker command failed with exit code 1 (use -v to see invocation) in Swift

iosxcodeswift

提问by simge

I used Swift language in my IOS application project in Xcode6 Beta6 and then I had to work on it with another computer. Then I got this error:

我在 Xcode6 Beta6 的 IOS 应用程序项目中使用了 Swift 语言,然后我不得不用另一台计算机来处理它。然后我得到了这个错误:

"clang: error: linker command failed with exit code 1 (use -v to see invocation)"

“clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)”

This error is shown only different computers than the computer on which I opened my project at first. It does not give an error in the first computer (which I opened and started to the project)

此错误仅显示与我最初打开项目的计算机不同的计算机。它不会在第一台计算机(我打开并开始项目)中出错

I tried to clean, and delete the contents of DerivedData folder, but it gives me the same error again. Below this error, it also says that "file not found:" for inside of the DerivedData folder:

我试图清理并删除 DerivedData 文件夹的内容,但它再次给了我同样的错误。在此错误下方,它还表示“未找到文件:”对于 DerivedData 文件夹内部:

file not found: /Users/macbook/Library/Developer/Xcode/DerivedData/SihirliSayilar-gmmsqkhqgygosqeuqdiibnrjasbq/Build/Products/Debug-iphonesimulator/Project.app/Project

找不到文件:/Users/macbook/Library/Developer/Xcode/DerivedData/SihirliSayilar-gmmsqkhqgygosqeuqdiibnrjasbq/Build/Products/Debug-iphonesimulator/Project.app/Project

I looked the other titles for this issue, but none of them solve this problem. Thank you for any help!

我看了这个问题的其他标题,但没有一个能解决这个问题。感谢您的任何帮助!

回答by csotiriou

The fact that it's a linker error should point you into the right direction. Compilation errors usually mean an error in your syntax. Linker error means that although your source files have been compiled correctly, but when the time comes to be linked with other frameworks (system frameworks, or 3rd party ones), clang cannot find them in place.

这是链接器错误的事实应该为您指明正确的方向。编译错误通常意味着语法错误。链接器错误意味着虽然您的源文件已经正确编译,但是当需要与其他框架(系统框架或第 3 方框架)链接时,clang 无法找到它们。

Usually, this is because a 3rd party library is missing from your system, and your project depends on it, and although it can find the header files, it cannot find the actual library file to connect to. The fact that transferring your project to other computers is giving you problems, while at your computer compiles and links correctly also strengthens the assumption that probably it's a problem with the environment you are trying to compile with and you need to install something.

通常,这是因为您的系统中缺少第 3 方库,而您的项目依赖于它,虽然它可以找到头文件,但无法找到要连接的实际库文件。将您的项目转移到其他计算机会给您带来问题,而在您的计算机上正确编译和链接这一事实也加强了这样一种假设,即可能是您尝试编译的环境存在问题并且您需要安装某些东西。

To find out more about the issue, go into Xcode, go into the report navigator, and you will see logs of all the builds you have made. Check the first one (which is the last build). Scroll to the bottom, and see exactly why it didn't compile. The most common scenario is that some symbol could not be found. Check in which library this symbol belongs, then install this library to your system.

要了解有关该问题的更多信息,请进入 Xcode,进入报告导航器,您将看到您所做的所有构建的日志。检查第一个(这是最后一个构建)。滚动到底部,看看它为什么没有编译。最常见的情况是找不到某些符号。检查此符号属于哪个库,然后将此库安装到您的系统中。

回答by Rahul Akula

I got same error you have mentioned. I have just clean the project and build it. It worked!

我遇到了你提到的同样错误。我刚刚清理了项目并构建了它。有效!

You can clean the project in Product Tab and select clean. To build select build in product tab in Xcode.

您可以在产品选项卡中清理项目并选择清理。要在 Xcode 中的产品选项卡中构建选择构建。

回答by shudeng wu

I encountered the same problem and my solution is as follow:

我遇到了同样的问题,我的解决方案如下:

Close the current project in xcode ---> Go to your project file and open the project by clicking the .xcworkspace file. Note: not the .xodeproj file.

在 xcode 中关闭当前项目 ---> 转到您的项目文件并通过单击 .xcworkspace 文件打开该项目。注意:不是 .xodeproj 文件。

Hope this helps!

希望这可以帮助!

回答by Swifty Codes

In My case it worked like this:

在我的情况下,它是这样工作的:

-> Click on the project
-> Go to "General" tab down there
-> Go to "Linked Frameworks & Libraries"
-> Click of the "+" button , you will find something like this -> Pods_yourProjectname.frameworkadd it
-> Then add the Frameworks that you have added from there only!
-> "Command+B" (Build your Project) and the combination "Shift+Command+K" (Clean your Project)
-> Run your Application.

-> 单击项目
-> 转到下面的“常规”选项卡
-> 转到“链接的框架和库”
-> 单击“+”按钮,您会发现类似这样的内容 ->Pods_yourProjectname.framework添加
-> 然后添加您仅从那里添加的框架!
->“Command+B”(构建您的项目)和组合“Shift+Command+K”(清理您的项目)
-> 运行您的应用程序。

回答by Mick

Simple Solution in my case:

在我的情况下的简单解决方案:

Product -> Clean

and then:

进而:

Product -> Run

回答by Illegal Argument

I faced this error when I opened .xcodeprojinstead of .xcworkspacewhile using cocoapods dependency manager.

当我使用 cocoapods 依赖管理器打开.xcodeproj而不是.xcworkspace时,我遇到了这个错误。

Make sure you are opening .xcworkspace. enter image description here

确保您正在打开.xcworkspace在此处输入图片说明

回答by BobCowe

I had the same error, and after digging through the logs I found the error "Duplicate Symbol"...

我有同样的错误,在翻阅日志后,我发现了错误“重复符号”......

After a heap of searching I found that I had #imported a ".m" file instead of a ".h"

经过大量搜索后,我发现我#imported了一个“.m”文件而不是“.h”

Maybe this might help someone.

也许这可能会帮助某人。

回答by iRiziya

In my case,

就我而言,

I faced the same clangerror when I opened myproject.xcodeprojfile instead of myproject.xcworkspaceby mistake after installing cocoapodsto my project.

在安装到我的项目后,clang当我打开myproject.xcodeproj文件而不是错误时,我遇到了同样的错误。myproject.xcworkspacecocoapods

回答by Ashkan Ghodrat

it can be anything in your code, for me it was a problem with coredata classes?:

它可以是您代码中的任何内容,对我来说这是 coredata 类的问题吗?:

@objc(Attribute) // the problem
class Category : NSManagedObject{
}

changed to

变成

@objc(Category)
class Category : NSManagedObject{
}

回答by tania_S

Set Host Application to your Project Target. Also, check the Allow testing Host Application APIs is turned on.

将宿主应用程序设置为您的项目目标。此外,检查允许测试主机应用程序 API 是否已打开。

enter image description here

在此处输入图片说明