将一个Xcode项目包含在另一个项目中-链接器错误 [英] Including one Xcode project in another -- linker errors

查看:94
本文介绍了将一个Xcode项目包含在另一个项目中-链接器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行此操作,并且遇到了问题.父项目需要从子项目访问类SettingsViewController.我已将子项目路径放入标题搜索路径.一切都可以编译,但是出现链接器错误,如下所示:

未定义符号:"_ OBJC_METACLASS _ $ _ SettingsViewController", 引用自: StatisticsViewController.o中的_OBJC_METACLASS _ $ _StatisticsViewController.o"_OBJC_CLASS _ $ _ SettingsViewController", 引用自: SelectionViewController.o中的objc-class-ref-to-SettingsViewController StatisticsViewController.o中的_OBJC_CLASS _ $ _ St​​atisticsViewController ld:找不到符号collect2:ld 返回了1个退出状态

我该如何解决?

解决方案

我认为子项目是静态库.当前,您的父项目知道如何找到子项目的头文件(否则将无法编译),但是它不知道它必须链接到子项目的库(.a)文件. /p>

您可能应该将库文件添加到 Targets> {您的应用}> Link Binary with Libraries .此外,您可能需要添加链接器标志-ObjC并可能添加-all_load.

网上有很多详细的说明,例如使用Xcode构建iPhone静态库.

更新:

如果它不是静态库,那么它是一个相当奇怪的项目设置.最好的办法是将共享文件(.h和.m)添加到两个项目中.然后,它们将在两个项目中独立编译.如果共享文件很少,那应该可以.

但是无论如何,我还是建议您将项目设置与静态库一起使用.如果正确设置,它会很好地工作.我已经成功使用了.而且-正如我之前所讲的-网上有几个很好的说明,如何设置它.

I am trying to do this, and running into problems. The parent project needs to access the class SettingsViewController from the child project. I have put the child project path into my header search paths. Everything compiles OK, but I get linker errors, as follows:

Undefined symbols: "_OBJC_METACLASS_$_SettingsViewController", referenced from: _OBJC_METACLASS_$_StatisticsViewController in StatisticsViewController.o "_OBJC_CLASS_$_SettingsViewController", referenced from: objc-class-ref-to-SettingsViewController in SelectionViewController.o _OBJC_CLASS_$_StatisticsViewController in StatisticsViewController.o ld: symbol(s) not found collect2: ld returned 1 exit status

How can I fix this?

解决方案

I assume the child project is a static library. Currently, your parent project knows how to find the header files of the child project (otherwise it wouldn't compile), but it doesn't know that it has to link to the library (.a) file of the child project.

You should probably add the library file to Targets > {your app} > Link Binary with Libraries. Furthermore, you probably need to add the linker flags -ObjC and possibly -all_load.

There are many detailed descriptions on the net, e.g. Build iPhone static library with Xcode.

Update:

If it's not a static library, then it's a rather strange project setup. The best thing you can do is to add the shared files (.h and .m) to both projects. They will then be independently compiled in both projects. That should work if you have few shared files.

But I recommend anyway to use a project setup with a static library. It nicely works if you properly set it up. I'm successfully using it. And - as I've told before - there a several good descriptions on the net how to set it up.

这篇关于将一个Xcode项目包含在另一个项目中-链接器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆