Including one Xcode project in another — linker errors

こ雲淡風輕ζ 提交于 2019-11-27 08:36:46

问题


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?


回答1:


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.




回答2:


You may be missing a framework. Can't really tell from what you have posted here though.




回答3:


I know this is very old but might be helpful for others.

You need to setup the included project in Target Dependencies in "Build Phases" to get the included projet to be compiled and you also should add the static library of the included project in the "Link Binary with Libraries".

Click on your Target->Build Phases and set these up.




回答4:


Undefined symbols is a linker error

1.Check if you have added a library or framework

Project editor -> select a target -> General -> Linked Frameworks and Libraries
//or
Project editor -> select a target -> Build Phases -> Link Binary With Libraries

2.If you try to use Swift code from Objective-C

Add empty .swift file to the Objective-C project. When Xcode ask press Create Bridging Header



来源:https://stackoverflow.com/questions/4529133/including-one-xcode-project-in-another-linker-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!