开发者

Including a dynamic library in an Xcode 4 project

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 an开发者_开发问答d 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜