xcode FacebookSDK for Unity iOS Mach-O 链接器错误 - 未定义符号 _iosLogin,

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20104990/
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-09-15 04:19:16  来源:igfitidea点击:

FacebookSDK for Unity iOS Mach-O linker error - undefined symbols _iosLogin,

iosxcodefacebookunity3d

提问by Martin ?ustek

I've added FacebookSDK into my Unity project according to tutorial here https://developers.facebook.com/docs/unity/getting-started/canvas/.

我已经根据https://developers.facebook.com/docs/unity/getting-started/canvas/ 的教程将 FacebookSDK 添加到我的 Unity 项目中。

It means that I've downloaded the SDK .unitypackage, imported it into Unity project and set application name and ID in configuration settings inspector.

这意味着我已经下载了 SDK .unitypackage,将其导入 Unity 项目并在配置设置检查器中设置应用程序名称和 ID。

When I try to build for device, Xcode build hangs on following Mach-O linker error:

当我尝试为设备构建时,Xcode 构建在出现以下 Mach-O 链接器错误时挂起:

Undefined symbols for architecture armv7:
  "_iosLogin", referenced from:
      RegisterMonoModules() in RegisterMonoModules.o
  "_iosLogout", referenced from:
      RegisterMonoModules() in RegisterMonoModules.o
  "_iosInit", referenced from:
      RegisterMonoModules() in RegisterMonoModules.o
  "_iosSetShareDialogMode", referenced from:
      RegisterMonoModules() in RegisterMonoModules.o
  "_iosFeedRequest", referenced from:
      RegisterMonoModules() in RegisterMonoModules.o
  "_iosAppRequest", referenced from:
      RegisterMonoModules() in RegisterMonoModules.o
  "_iosFBSettingsPublishInstall", referenced from:
      RegisterMonoModules() in RegisterMonoModules.o
  "_iosFBAppEventsSetLimitEventUsage", referenced from:
      RegisterMonoModules() in RegisterMonoModules.o
  "_iosGetDeepLink", referenced from:
      RegisterMonoModules() in RegisterMonoModules.o
  "_iosFBAppEventsLogPurchase", referenced from:
      RegisterMonoModules() in RegisterMonoModules.o
  "_iosFBAppEventsLogEvent", referenced from:
      RegisterMonoModules() in RegisterMonoModules.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

It looks like Unity, Xcode or me forgot to include some library, search path or source file somewhere. Can you help me to find out what happened wrong? Do you know in which file this symbols should be or how to setup linker?

看起来 Unity、Xcode 或我忘记在某处包含一些库、搜索路径或源文件。你能帮我找出发生了什么问题吗?你知道这个符号应该在哪个文件中或者如何设置链接器吗?

Unity 4.3.0f4 (also tried 4.2.?)
Facebook SDK 4.3.4 (also tried 4.3.3)
Xcode 5.0.2, deployment target 4.0 (also tried 6.1)

回答by Clay Fowler

Those symbols are exported from FacebookSDK.a, which should be getting included into your Xcode project by the [PostProcessBuild] step in /Assets/Facebook/Editor/FacebookPostprocess.cs. That file actually spins through all of the files in your project that end with ".projmods" in their filename and applies them as transformations to your xcode project. I've seen 2 things go wrong here when having this kind of problem:

这些符号是从 FacebookSDK.a 导出的,应该通过 /Assets/Facebook/Editor/FacebookPostprocess.cs 中的 [PostProcessBuild] 步骤将其包含到您的 Xcode 项目中。该文件实际上会遍历项目中文件名中以“.projmods”结尾的所有文件,并将它们作为转换应用于 xcode 项目。遇到此类问题时,我已经看到两件事出错了:

  1. I had removed either FacebookPostprocess.cs or some of the ".projmods" files from my project accidentally. Check that both exist. The specific projmods file in this case should be at /Assets/Facebook/Editor/iOS.
  2. You have your own [PostProcessBuild] steps that clobber Facebook's changes. You can fix this by applying the optional "order" parameter to the PostProcessBuild attribute.
  1. 我不小心从我的项目中删除了 FacebookPostprocess.cs 或一些“.projmods”文件。检查两者是否存在。在这种情况下,特定的 projmods 文件应位于 /Assets/Facebook/Editor/iOS。
  2. 您有自己的 [PostProcessBuild] 步骤来破坏 Facebook 的更改。您可以通过将可选的“order”参数应用于 PostProcessBuild 属性来解决此问题。

You can also check in Xcode that FacebookSDK.a is, indeed, in the /Libraries group of the project and that under "Build Phases" it is included as a binary to link with.

您还可以在 Xcode 中检查 FacebookSDK.a 确实在项目的 /Libraries 组中,并且在“构建阶段”下它作为要链接的二进制文件包含在内。

Also look carefully at the log output from Unity when you build. Sometimes the projmods postprocessor will complain about files not found, etc.

构建时还要仔细查看 Unity 的日志输出。有时 projmods 后处理器会抱怨找不到文件等。

回答by Jeremy Nikolai

One other potential cause of this: the Facebook SDK uses a third-party library XCode-Editor-for-Unityto do it's XCode project postprocessing. If any other middleware in your project uses this as well, you'll potentially have duplicate instances of it.

另一个可能的原因是:Facebook SDK 使用第三方库XCode-Editor-for-Unity进行 XCode 项目后处理。如果您的项目中的任何其他中间件也使用它,您可能会拥有它的重复实例。

In our case, the SponsorPay api also had a copy of this library, and when importing the Facebook API it was overwriting SponsorPay's implementation of it (which had some modifications from the original library).

在我们的例子中,SponsorPay api 也有这个库的副本,当导入 Facebook API 时,它覆盖了 SponsorPay 的实现(对原始库进行了一些修改)。

This took a few steps to fix:

这需要几个步骤来修复:

First, move each instance to its own namespace, and fix the references to them:

首先,将每个实例移动到它自己的命名空间,并修复对它们的引用:

in Facebook/Editor/iOS/XCodeEditor-for-Unity/*.cs:

在 Facebook/Editor/iOS/XCodeEditor-for-Unity/*.cs 中:

namespace UnityEditor.XCodeEditor.Facebook
{
    ...
}

and in Facebook/Editor/FacebookPostprocess.cs:

在 Facebook/Editor/FacebookPostprocess.cs 中:

// our 'XCProject' is now in the UnityEditor.XCodeEditor.Facebook namespace
UnityEditor.XCodeEditor.Facebook.XCProject project =
    new UnityEditor.XCodeEditor.Facebook.XCProject(path);

... And do the same for the other library.

... 对另一个库做同样的事情。



Once we had this fixed, we ran into one last problem: Each library's Postprocess script was walking over the entire project to find .projmodsfiles, which meant each of these files got processed twice (once by the wrong implementation, which triggered another crash).

一旦我们解决了这个问题,我们就遇到了最后一个问题:每个库的 Postprocess 脚本都在遍历整个项目以查找.projmods文件,这意味着这些文件中的每一个都被处理了两次(一次是由于错误的实现,导致了另一次崩溃)。

So, one last step, make sure each of the libraries is postprocessing only its own path:

因此,最后一步,请确保每个库仅对自己的路径进行后处理:

// Find and run through all projmods files to patch the project

// Set this to your project's Facebook API location:
string sdkPath = "Facebook/Editor/iOS";
string projModPath = System.IO.Path.Combine(Application.dataPath, sdkPath)
var files = System.IO.Directory.GetFiles(projModPath, "*.projmods", System.IO.SearchOption.AllDirectories);

foreach (var file in files)
{
    project.ApplyMod(Application.dataPath, file);
}
project.Save();

and again, doublecheck this for the other library as well.

再一次,也为另一个库仔细检查这个。