[Solved] Struggling to run my first Magick++ program

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
h1b1
Posts: 3
Joined: 2017-08-17T08:31:07-07:00
Authentication code: 1151

[Solved] Struggling to run my first Magick++ program

Post by h1b1 » 2017-08-17T08:40:55-07:00

Hi Everyone,

I want to run a simple c++ program that includes the line

Code: Select all

#inlcude <Magick++>
but the compiler throws the error

Code: Select all

fatal error: Magick++.h: No such file or directory
compilation terminated.
For installation, I cloned ImageMagick from GitHub to my home directory, and then ran ./configure, make and make install.

OS: macOS Sierra
Compiler: g++
ImageMagick version: 7
Also used Homebrew to install libxml2 and other missing libraries.

Any help would be much appreciated! Thanks!
Last edited by h1b1 on 2017-08-17T10:11:36-07:00, edited 1 time in total.

snibgo
Posts: 9404
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Struggling to run my first Magick++ program

Post by snibgo » 2017-08-17T08:46:00-07:00

It might help if you showed the compiler command you used. This should contain something that says where to find include files.
snibgo's IM pages: im.snibgo.com

h1b1
Posts: 3
Joined: 2017-08-17T08:31:07-07:00
Authentication code: 1151

Re: Struggling to run my first Magick++ program

Post by h1b1 » 2017-08-17T08:50:30-07:00

Thanks for the reply.

The compiler command was simply g++ test.cpp

When I tried

Code: Select all

 g++ -I /usr/local/include/ImageMagick-7/ test.cpp
I got the following:

Code: Select all

In file included from /usr/local/include/ImageMagick-7/Magick++/Include.h:14:0,
                 from /usr/local/include/ImageMagick-7/Magick++.h:10,
                 from test.cpp:1:
/usr/local/include/ImageMagick-7/MagickCore/magick-config.h:29:3: warning: #warning "you should set MAGICKCORE_QUANTUM_DEPTH to sensible default set it to configure time default" [-Wcpp]
 # warning "you should set MAGICKCORE_QUANTUM_DEPTH to sensible default set it to configure time default"
   ^
/usr/local/include/ImageMagick-7/MagickCore/magick-config.h:30:3: warning: #warning "this is an obsolete behavior please fix your makefile" [-Wcpp]
 # warning "this is an obsolete behavior please fix your makefile"
   ^
/usr/local/include/ImageMagick-7/MagickCore/magick-config.h:52:3: warning: #warning "you should set MAGICKCORE_HDRI_ENABLE to sensible default set it to configure time default" [-Wcpp]
 # warning "you should set MAGICKCORE_HDRI_ENABLE to sensible default set it to configure time default"
   ^
/usr/local/include/ImageMagick-7/MagickCore/magick-config.h:53:3: warning: #warning "this is an obsolete behavior please fix yours makefile" [-Wcpp]
 # warning "this is an obsolete behavior please fix yours makefile"
   ^
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

snibgo
Posts: 9404
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Struggling to run my first Magick++ program

Post by snibgo » 2017-08-17T09:30:34-07:00

Can you successfully build the supplied demo programs? Or have you skipped that stage?

The official docs http://www.imagemagick.org/script/magick++.php contain a build line that contain a couple of calls to Magick++-config. Have you deliberately chosen not to do this?
snibgo's IM pages: im.snibgo.com

h1b1
Posts: 3
Joined: 2017-08-17T08:31:07-07:00
Authentication code: 1151

Re: Struggling to run my first Magick++ program

Post by h1b1 » 2017-08-17T10:06:15-07:00

Can you successfully build the supplied demo programs?
Yes, but I think that was my mistake.

I thought I had to run the line

Code: Select all

c++ `Magick++-config --cxxflags --cppflags` -O2 -o demo demo.cpp \
  `Magick++-config --ldflags --libs`
and

Code: Select all

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
with some demo file as a configuration step only once, and didn't realize that's how to compile c++ programs that use <Magick++.h>.

So now my problem is solved! Thanks a lot for your help!

tbone
Posts: 3
Joined: 2017-08-19T15:02:12-07:00
Authentication code: 1151

Re: [Solved] Struggling to run my first Magick++ program

Post by tbone » 2017-08-19T15:33:42-07:00

I am having similar problem. When I try to run the sample code in VS environment, I provided the "include" and "lib" path properly but I still get linker errors like this, any ideas? I added the install folder "C:\Program Files\ImageMagick-7.0.6-Q16" to "PATH" of the project, assuming it is dll related issue and it isnt solving either.


Error LNK2019 unresolved external symbol "void __cdecl Magick::InitializeMagick(char const *)" (?InitializeMagick@Magick@@YAXPEBD@Z) referenced in function main ImageMagic_101

Post Reply