在 Xcode 4 项目中包含动态库
我对这个基本问题表示歉意。我一直在寻找一个简单的答案,但到目前为止我还没有成功,所以我希望这对其他初学者程序员有所帮助。
我已经安装了 MacPorts,然后安装了我想要的外部库:ImageMagick
。根据我的研究,我知道 MacPorts 将 dylib 放在 /opt/local/lib/
文件夹中: 图片。我还知道头文件位于 /opt/local/include/ImageMagick/
文件夹中。
我想我应该从一个 示例程序 开始,看看它是如何运行的。我创建了一个新项目,一个 C 命令行工具,然后将第一个示例复制到 main.c
中。我现在想将 ImageMagick 库添加到我的项目中。
然后,如何将这些文件与我的 Xcode 项目链接起来,以便 #include
正常工作?
I apologise for the basic question. I've searched high an low for a simple answer but I have so far been unsuccessful, so I hope this helps other beginner programmers.
I've installed MacPorts and then installed the external library I was after: ImageMagick
. From my research I know that MacPorts put the dylibs in the /opt/local/lib/
folder: image. I also know that the header files are located in the /opt/local/include/ImageMagick/
folder.
I thought I'd start with an example program to see how it ran. I made a new project, a C command line tool, then copied the first example into main.c
. I now want to add the ImageMagick libraries to my project.
How do I then link the files with my Xcode project so that #include <wand/MagickWand.h>
works?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在 iPad 项目的外部库方面也遇到了类似的困难。似乎无法让模拟器和设备构建都满意。但是,对于您的测试用例,您可以尝试以下操作:
现在只需修改“调试”项和一个包含路径指令,例如 -
上面将允许您的代码进行编译,但现在您需要将其链接。您将需要添加额外的链接选项。
现在修改“调试”子项。有几种方法可以添加所需的库:
库搜索路径和库指令如下
<前><代码>-L/opt/local/lib -lImageMagic
具有库的完整路径
这些更改对我有用,至少在我找到真正的 XCode 4 方法之前是这样。这远不是正确的方法。希望有人找到了正确的方法。
I have similar difficulty with external libraries with iPad projects. Can't seem to make both the simulator and device builds happy. However, for your test case you could try the following:
For now just modify the Debug item and an include path directive like -
The above will allow your code to compile, but now you will need to get it to link. You will need to add an additional link option.
For now modify the "Debug" sub item. There are couple ways to add your desired library:
With a library search path and library directive as follows
With a full path to library
These changes worked for me, at least until I find real XCode 4 way to do it. This is far to clumsy to be the proper approach. Hope some has figured out right way.