j3py
j3py

Reputation: 1257

C Compile Fatal Error 'file not found' from ImageMagick Install Mac OS

I am trying to compile a C program that requires Image Magick's MagickWand.h:

#include "wand/MagickWand.h"

But my Image Magick was installed through Homebrew on my Mac so I changed the include to the actual location:

#include </usr/local/Cellar/imagemagick/6.8.9-7/include/ImageMagick-6/wand/MagickWand.h>

However, when I compiled the program I received the following error:

/usr/local/Cellar/imagemagick/6.8.9-7/include/ImageMagick-6/wand/MagickWand.h:71:10: fatal error: 'wand/method-attribute.h' file not found
#include "wand/method-attribute.h"

Now I've been going into the .h files when this error crops up and changing their #includes so that they are pointed correctly (because that appears to be the problem), but there is always a new error here and I'd rather not spend hours manually updating these because of a Homebrew install. Does anyone have any suggestions on how to fix this without manually updating each file? I'm not sure exactly what the problem is so perhaps there is a more elegant solution.

Upvotes: 0

Views: 1289

Answers (1)

emcconville
emcconville

Reputation: 24419

Your code should include the MagickWand library as system headers, and keep the generic path. This will keep your future compiling from breaking when the system/library updates.

#include <wand/MagickWand.h>

Tell your C compiler where homebrew installed ImageMagick by setting the preprocessor include flag -I, and linking/library options with the -L & -l flags.

example:

clang -I/usr/local/Cellar/imagemagick/6.8.9-7/include/ImageMagick-6 \
      myProject.c -o myProject.o \
      -L/usr/local/Cellar/imagemagick/6.8.9-7/lib \
      -lMagickWand-6.Q16 \
      -lMagickCore-6.Q1

To simplify the whole process, ImageMagick ships MagickWand-config utility. This will take care of libs, includes, and definitions for you.

example:

CFLAGS=$(MagickWand-config --cflags)
LFLAGS=$(MagickWand-config --libs)
clang $CFLAGS myProject.c -o myProject.o $LFLAGS

Upvotes: 1

Related Questions