1

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?

brendanzab
  • 950
  • 1
  • 11
  • 29

1 Answers1

2

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.

Luke Van In
  • 5,215
  • 2
  • 24
  • 45
tralfaz
  • 31
  • 3
  • I'll let you know how it goes when I get a chance to test it out. I've currently been going through the Stanford lectures to get a more solid understanding of the SDK before I get my hands dirty with ImageMagik. – brendanzab Apr 07 '11 at 04:14
  • This is interesting: http://stackoverflow.com/questions/458805/force-static-linking-of-library-linked-to-xcode-target ...it seems you can't actually include dymamic libraries in an ios project. Which I neglected to say was the intended project I had in mind. – brendanzab May 02 '11 at 09:54