How do I change an existing Xcode target from dynamic to static?

给你一囗甜甜゛ 提交于 2020-01-01 04:15:50

问题


I'm working with an existing project that produces a dynamic library (Cocoa API).

I'd rather generate a static library, but if I change the [Linking|Mach-O Type] field from "Dynamic Library" to "Static Library", both the Clean Project and Build Project complain that the target has an invalid MACH_O_TYPE value of 'staticlib'.

Is there a straightforward way to get the build to produce a static .a file?

Thanks,
Eric


回答1:


Opens up the project.pbxproj file in YourProjectName.xcodeproj folder using TextEdit, search for productType and change it's value from "com.apple.product-dynamic" to "com.apple.product-static"




回答2:


I ended up creating a new 'static library' project, and then added all the members. Closing xcode and bringing up the two project files in a text editor let me quickly complete the new project.




回答3:


I managed to do this, with the help of this post and a bit of digging around. Additional changes I had to make were changing compiled.mach-o.dylib to archive.ar and changing various references in the project file (including inside comments, call me pedantic) from foo.dylib to libfoo.a.

I also had to create a new 'scheme' before it would build, but that might be because I changed the name of the project, I'm not sure. Also, any frameworks referenced by the library need to be added to the application(s) that link against it when you move from .dylib to .a.

It was well worth persevering though as it preserved all the subtleties of the original project (such as building a 32/64 fat binary for release but not for debugging). Result.



来源:https://stackoverflow.com/questions/1349115/how-do-i-change-an-existing-xcode-target-from-dynamic-to-static

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