10

Hoping someone can help me out as I'm at a complete loss. I've trawled the Internet and really can't find anything more to help me.

I'm trying to compile my c++ program which uses the Magick++ library. I've installed Magick++ seemingly fine. In my current directory is located main.cpp and I'm running g++ main.cpp. I'm getting the following error...

In file included from main.cpp:3:0:
/home/simeon/ImageMagick-6.8.9-0/Magick++/lib/Magick++.h:9:30: fatal error: Magick++/Include.h: No such file or directory
compilation terminated.

To try and get around the problem I'm declaring the absolute path to Magick++.h in my main.cpp so I have this which seems to be working...

#include "/home/simeon/ImageMagick-6.8.9-0/Magick++/lib/Magick++.h"

The error occurs on line 9 in Magick++.h (which it's finding due to me absolute path) which looks like this...

#include <Magick++/Include.h>

This is where I'm confused because this file does exist in the place it says it is. If I run

 cat /home/simeon/ImageMagick-6.8.9-0/Magick++/lib/Magick++/Include.h

then the file opens without problem and shows its contents.

Does anyone have any suggestions as to what's going on please? I don't understand why I need to specify an absolute path at all and why g++ isn't finding the header files in the first place. Is there somehow I can tell g++ to look for Magick++ headers in a specific place?

Thanks in advance! Simeon

Simeon Rowsell
  • 303
  • 1
  • 3
  • 9
  • This might be useful: http://www.imagemagick.org/Magick++/ (under the Usage section). It seems like you installed the library manually into your home directory, which isn't right. You should have followed the instructions here: http://www.imagemagick.org/Magick++/Install.html. That in itself is not the problem, but you need to do that before you can use the instructions in the first link. – Chris Laplante Apr 27 '14 at 17:46

3 Answers3

12

Since you are under Linux, I would think you can install the imagemagick package that comes with your installation. It's available on all flavors of Linux I know of.

Under Debian/Ubuntu it would be something like this:

sudo apt-get install libmagick++-dev

Otherwise, I personally would use cmake to do all the setup. It's a bit of a learning curve at first, but then it automates those things for you.

It seems to me that if your command line is:

g++ main.cpp

Then you are missing a couple of -I options. Installing the package may not require you to use the -I option (since I use cmake and don't really pay attention to those things... it just works for me.)

So to solve your problem, you probably need something like this:

g++ -I/home/simeon/ImageMagick-6.8.9-0/Magick++/lib main.cpp

Also, if you have a single .cpp file, you may want to use a -o myprog command line option.

For the compile and link steps to work as expected, you may want to use the pkgconfig definitions of Magick

# compile
pkg-config --cflags /usr/lib/x86_64-linux-gnu/pkgconfig/ImageMagick++.pc

# link
pkg-config --libs /usr/lib/x86_64-linux-gnu/pkgconfig/ImageMagick++.pc

These commands are actually what cmake would try to use to determine the compile time and link time additional flags.

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
2

ImageMagick ships with a configuration utility that should give you the correct path. For Magick++, it's simply Magick++-config (see section Usage in Magick++ docs.)

IM_CXXFLAGS=$(Magick++-config --cxxflags)
IM_LDFLAGS=$(Magick++-config --ldflags)
g++ $IM_CXXFLAGS $IM_LDFLAGS main.cpp

You will need to use the system's include statement (<>), and keep it simple by including the parent header.

#include <Magick++.h>
ynn
  • 3,386
  • 2
  • 19
  • 42
emcconville
  • 23,800
  • 4
  • 50
  • 66
2

If you just need it for single file, here is the proper build command for a Magick++ module:

g++ `Magick++-config --cxxflags --cppflags` -O2 -Wall -o yourProgramName yourFile.cpp `Magick++-config --ldflags --libs`

If it does not work you may need to install libmagick++-dev first:

sudo apt-get install libmagick++-dev

And install imageMagick from Unix Source:

  1. download ImageMagick-7.0.3-5.tar.gz from here
  2. Install it using instructions from here
Sxl
  • 127
  • 8
  • Interesting, although on Ubuntu it tells me that the `Magick++-config` tool can be installed with `sudo apt install graphicsmagick-libmagick-dev-compat`, which to me makes it sound like it's either deprecated or not expected to be used under Debian/Ubuntu. – Alexis Wilke Sep 22 '21 at 22:50