如何将现有的 Xcode 目标从动态更改为静态?

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

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

xcodexcodebuild

提问by Eric

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

我正在使用一个生成动态库(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_TYPEvalue of 'staticlib'.

我宁愿生成一个静态库,但是如果我将 [Linking|Mach-O Type] 字段从“Dynamic Library”更改为“Static Library”,则 Clean Project 和 Build Project 都会抱怨目标的MACH_O_TYPE值无效'静态库'。

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

有没有一种直接的方法可以让构建生成静态 .a 文件?

Thanks,
Eric

谢谢,
埃里克

回答by Ricky Lung

Opens up the project.pbxprojfile in YourProjectName.xcodeprojfolder using TextEdit, search for productTypeand change it's value from "com.apple.product-dynamic" to "com.apple.product-static"

使用 TextEdit打开YourProjectName.xcodeproj文件夹中的project.pbxproj文件,搜索productType并将其值从“ com.apple.product-dynamic”更改为“ com.apple.product-static

回答by Eric

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.

我最终创建了一个新的“静态库”项目,然后添加了所有成员。关闭 xcode 并在文本编辑器中调出两个项目文件让我快速完成新项目。

回答by Paul Sanders

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.dylibto archive.arand changing various references in the project file (including inside comments, call me pedantic) from foo.dylibto libfoo.a.

在这篇文章的帮助下,我设法做到了这一点,并进行了一些挖掘。我必须进行的其他更改是将compiled.mach-o.dylib更改为archive.ar并将项目文件中的各种引用(包括内部注释,称我为迂腐)从foo.dylib 更改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.

我还必须在构建之前创建一个新的“方案”,但这可能是因为我更改了项目的名称,我不确定。此外,当您从 .dylib 移动到 .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.

尽管如此,坚持还是很值得的,因为它保留了原始项目的所有细微之处(例如构建一个 32/64 的胖二进制用于发布而不是用于调试)。结果。