在 Xcode 4 项目中包含动态库

发布于 2024-10-27 07:43:52 字数 615 浏览 4 评论 0原文

我对这个基本问题表示歉意。我一直在寻找一个简单的答案,但到目前为止我还没有成功,所以我希望这对其他初学者程序员有所帮助。

我已经安装了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我早已燃尽 2024-11-03 07:43:53

我在 iPad 项目的外部库方面也遇到了类似的困难。似乎无法让模拟器和设备构建都满意。但是,对于您的测试用例,您可以尝试以下操作:

  1. 在项目导航器中选择您的项目。应该是最上面的项目。
  2. 在最顶部的详细信息窗格中,您应该看到选项卡标签列表,选择“构建设置”选项卡。
  3. 向下滚动直到找到“LLVM GCC 4.2 - 语言”部分。
  4. 找到“Other C Flags”,并根据需要展开它。您将看到两个子项“调试”和“发布”。
  5. 现在只需修改“调试”项和一个包含路径指令,例如 -

    I/opt/local/include/ImageMagick
    

上面将允许您的代码进行编译,但现在您需要将其链接。您将需要添加额外的链接选项。

  1. 在构建设置面板中找到“链接”部分。
  2. 在“链接”部分中找到“其他链接器标志”并根据需要展开它。
  3. 现在修改“调试”子项。有几种方法可以添加所需的库:

    库搜索路径和库指令如下

    <前><代码>-L/opt/local/lib -lImageMagic

    具有库的完整路径

    /opt/local/lib/libImageMagic.dylib (请注意,这是实际的文件名)
    

这些更改对我有用,至少在我找到真正的 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:

  1. In the project navigator select your project. Should be top most item.
  2. In the detail pane at the very top you should see a list of tab labels, select the "Build Settings" tab.
  3. Scroll down till you find the "LLVM GCC 4.2 - Language" section.
  4. Find the "Other C Flags", and expand it if needed. You will see two sub items Debug and Release.
  5. For now just modify the Debug item and an include path directive like -

    I/opt/local/include/ImageMagick
    

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.

  1. In the build settings panel find the "Linking" section.
  2. Within the "Linking" section find the "Other Linker Flags" and expand it if needed.
  3. 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

    -L/opt/local/lib -lImageMagic
    

    With a full path to library

    /opt/local/lib/libImageMagic.dylib  (note sure that is the actual file name)
    

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文