在 Xcode 中构建和使用 DYLIB
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3955272/
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
Building and Using a DYLIB in Xcode
提问by Justin Mrkva
I'm trying to build a .dylib in Xcode. Currently the .dylib builds, but when I drag the .dylib into another project and try to #import one of the headers (Seeker.h) in the .dylib, I get this error:
我正在尝试在 Xcode 中构建一个 .dylib。当前 .dylib 构建,但是当我将 .dylib 拖入另一个项目并尝试 #import .dylib 中的一个标头 (Seeker.h) 时,我收到此错误:
*: No such file or directory
Seeker.h: No such file or directory
*: 没有
那个文件或目录Seeker.h: 没有那个文件或目录
The project is available as an Xcode project here.
该项目可在此处作为 Xcode 项目使用。
I can confirm the header is indeed in a path alongside the .dylib once built, but as for what to do with it I have no idea. My only experience with .dylib files is frameworks built into Mac OS X, like libsqlite3.dylib, which works perfectly. All the tutorials I can find on .dylib files does not cover how to use them with Xcode in a sensible manner; all of them rely either on complex scripts or machine-dependent configuration which will not work for us.
我可以确认标题确实在构建后的 .dylib 旁边的路径中,但至于如何处理它我不知道。我对 .dylib 文件的唯一经验是 Mac OS X 中内置的框架,例如 libsqlite3.dylib,它运行良好。我可以在 .dylib 文件上找到的所有教程都没有涵盖如何以合理的方式在 Xcode 中使用它们;所有这些都依赖于复杂的脚本或依赖于机器的配置,这对我们不起作用。
So basically I need a start-to-finish step-by-step process that successfullybuilds the .dylib and successfullyincludes it in another Xcode project in a way that's not dependent on changing build settings for different users. In other words, a way that just works and that will work when we distribute both projects to members of our team.
所以基本上我需要一个从头到尾的分步过程,成功构建 .dylib 并成功地将它包含在另一个 Xcode 项目中,而不依赖于为不同用户更改构建设置。换句话说,当我们将两个项目分发给我们的团队成员时,这种方式行之有效。
回答by zneak
Dylibs don't carry headers: they're brainless executable files. Built-in libraries have their headers in known locations, like /usr/include
, which makes them globally available. What you're looking for is probably a framework.
Dylib 不带有标题:它们是无脑的可执行文件。内置库的标头位于已知位置,例如/usr/include
,这使它们在全球范围内可用。您正在寻找的可能是一个框架。
Frameworks are packages that contain a dynamic library and header files, so once you link with the framework you can import the headers it has. It can also carry other resources such as images and sounds.
框架是包含动态库和头文件的包,因此一旦与框架链接,您就可以导入它的头文件。它还可以承载其他资源,例如图像和声音。
I suggest you read the Framework Programming Guidefor more informations.
我建议您阅读框架编程指南以获取更多信息。