尝试访问子项目文件时从错误 xcode 引用的“_OBJC_CLASS_$_”

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

"_OBJC_CLASS_$_" referenced from error xcode when trying to access subproject files

iosxcode

提问by rohinb

I am using a subproject within my xcode project with files I want to access in my main project. I have put the directories to these files in my "Header Search Paths" in my build settings, so when I import them I don't get any compiler errors. I have the subproject files added to the the compile sources in the Build Phases of my subproject. I have my main project's files added to the compile sources of my main project. However, when I try to build, I get the following errors:

我在我的 xcode 项目中使用了一个子项目,其中包含我想在主项目中访问的文件。我已将这些文件的目录放在我的构建设置中的“标题搜索路径”中,因此当我导入它们时,我不会收到任何编译器错误。我将子项目文件添加到我的子项目的构建阶段中的编译源中。我将主项目的文件添加到主项目的编译源中。但是,当我尝试构建时,出现以下错误:

Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_LoginService", referenced from:
objc-class-ref in GettingStartedViewController.o
"_OBJC_CLASS_$_ProfileService", referenced from:
objc-class-ref in GettingStartedViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any ideas on fixing this? Is there a good way to add the subproject's files to the compile sources of the main project? When I do this, it creates a separate group in xcode without actually adding the files to the compile sources of the main project.
Thanks!

关于解决这个问题的任何想法?有没有什么好的方法可以将子项目的文件添加到主项目的编译源中?当我这样做时,它会在 xcode 中创建一个单独的组,而没有将文件实际添加到主项目的编译源中。
谢谢!

回答by Mobile Ben

The linker is complaining because it cannot find those symbols. Assuming that LoginService and ProfileService are from your sub-projects, what you will need to do is add those libraries (presumably the target built from the sub-project) to "Link Binary With Libraries" in the Build Phases.

链接器正在抱怨,因为它找不到这些符号。假设 LoginService 和 ProfileService 来自您的子项目,您需要做的是将这些库(大概是从子项目构建的目标)添加到 Build Phases 中的“Link Binary With Libraries”。

Additionally, you need to double check your Scheme for the main target you are building for and ensure that the targets for those sub-projects are being built (this would be in the Build stage shown on the left-side the Scheme dialog). If not, you will need to add them.

此外,您需要仔细检查您正在构建的主要目标的 Scheme,并确保正在构建这些子项目的目标(这将在 Scheme 对话框左侧显示的构建阶段)。如果没有,您将需要添加它们。

This is adding the library to the scheme. Note that if you have "Find Implicit Dependencies" checked, you should not have to do anything. I built a test case to double check (using Xcode 7.3.1)

这是将库添加到方案中。请注意,如果您选中了“查找隐式依赖项”,则无需执行任何操作。我构建了一个测试用例来仔细检查(使用 Xcode 7.3.1)

enter image description here

在此处输入图片说明