newbie needs help compiling a simple Magick++ program

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
mixersoft
Posts: 6
Joined: 2008-05-08T16:36:10-07:00

newbie needs help compiling a simple Magick++ program

Post by mixersoft »

hi,

I've got a bit of experience with PHP, Java, etc., but new to C++. I'm just trying to compile one of the test programs found in Magick++. I am using ubuntu linux , Eclipse 3.2.2, and CDT 3.1.2. here is what I have done so far.

- File>New>Managed Make C++ project
- File>New>Source File, created a new file main.cpp
- copy/paste code from ./ImageMagick-6.5.1-0/Magick++/tests/readWriteImages.cpp to main.cpp

Code: Select all

// This may look like C code, but it is really -*- C++ -*-
//
// Copyright Bob Friesenhahn, 1999, 2000, 2003
//
// Test STL readImages and writeImages functions
//

#include <Magick++.h>
#include <string>
#include <iostream>
#include <list>
#include <vector>

using namespace std;

using namespace Magick;

int main( int /*argc*/, char ** argv)
{

  // Initialize ImageMagick install location for Windows
  InitializeMagick(*argv);

  int failures=0;

[ plus a bit more...]
- Project>Properties>C/C++ Build>GCC C++ Linker > Miscellaneous>Linker Flags, added

Code: Select all

`Magick++-config --cppflags --cxxflags --ldflags --libs`
- Project>Properties>C/C++ Build>GCC C++ Compiler>Directories, added

Code: Select all

/path/to/ImageMagick-6.5.1-0/Magick++/lib
- When I "Build Project" I get the following output

Code: Select all

**** Build of configuration Debug for project test ****
make -k all 
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o"main.o" "../main.cpp"
../main.cpp:8:22: error: Magick++.h: No such file or directory
...
- right click on main.cpp, choose Properties>C/C++ Build>GCC C++ Compiler>Directories, added

Code: Select all

/path/to/ImageMagick-6.5.1-0/Magick++/lib
Now when I "Build Project" the compiler finds Magick++.h, but I get these errors:

Code: Select all

                 from ../main.cpp:8:
/path/to/ImageMagick-6.5.1-0/Magick++/lib/Magick++/Image.h:88: error: expected ‘,’ or ‘...’ before ‘type_’
/path/to/ImageMagick-6.5.1-0/Magick++/lib/Magick++/Image.h:89: error: ISO C++ forbids declaration of ‘StorageType’ with no type
/path/to/ImageMagick-6.5.1-0/Magick++/lib/Magick++/Image.h:125: error: expected ‘,’ or ‘...’ before ‘noiseType_’
/path/to/ImageMagick-6.5.1-0/Magick++/lib/Magick++/Image.h:125: error: ISO C++ forbids declaration of ‘NoiseType’ with no type
/path/to/ImageMagick-6.5.1-0/Magick++/lib/Magick++/Image.h:126: error: expected ‘,’ or ‘...’ before ‘channel_’
/path/to/ImageMagick-6.5.1-0/Magick++/lib/Magick++/Image.h:127: error: ISO C++ forbids declaration of ‘ChannelType’ with no type
/path/to/ImageMagick-6.5.1-0/Magick++/lib/Magick++/Image.h:154: error: expected ‘,’ or ‘...’ before ‘gravity_’
/path/to/ImageMagick-6.5.1-0/Magick++/lib/Magick++/Image.h:154: error: ISO C++ forbids declaration of ‘GravityType’ with no type
/path/to/ImageMagick-6.5.1-0/Magick++/lib/Magick++/Image.h:159: error: expected ‘,’ or ‘...’ before ‘gravity_’
/path/to/ImageMagick-6.5.1-0/Magick++/lib/Magick++/Image.h:160: error: ISO C++ forbids declaration of ‘GravityType’ with no type
/path/to/ImageMagick-6.5.1-0/Magick++/lib/Magick++/Image.h:160: error: ‘void Magick::Image::annotate(const std::string&, const Magick::Geometry&, int)’ cannot be overloaded
/path/to/ImageMagick-6.5.1-0/Magick++/lib/Magick++/Image.h:154: error: with ‘void Magick::Image::annotate(const std::string&, const Magick::Geometry&, int)’
/path/to/ImageMagick-6.5.1-0/Magick++/lib/Magick++/Image.h:164: error: expected ‘,’ or ‘...’ before ‘gravity_’
/path/to/ImageMagick-6.5.1-0/Magick++/lib/Magick++/Image.h:164: error: ISO C++ forbids declaration of ‘GravityType’ with no type

[ a whole lot more...]

../main.cpp:48:   instantiated from here
/path/to/ImageMagick-6.5.1-0/Magick++/lib/Magick++/STL.h:1764: error: ‘class Magick::Image’ has no member named ‘image’
/path/to/ImageMagick-6.5.1-0/Magick++/lib/Magick++/STL.h: In function ‘void Magick::unlinkImages(InputIterator, InputIterator) [with InputIterator = std::_List_iterator<Magick::Image>]’:
/path/to/ImageMagick-6.5.1-0/Magick++/lib/Magick++/STL.h:2344:   instantiated from ‘void Magick::writeImages(InputIterator, InputIterator, const std::string&, bool) [with InputIterator = std::_List_iterator<Magick::Image>]’
../main.cpp:48:   instantiated from here
/path/to/ImageMagick-6.5.1-0/Magick++/lib/Magick++/STL.h:1787: error: ‘class Magick::Image’ has no member named ‘image’
make: *** [main.o] Error 1
make: Target `all' not remade because of errors.
Build complete for project test
Can someone offer a suggestion as to what I'm doing wrong?

Many thanks.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: newbie needs help compiling a simple Magick++ program

Post by magick »

Try the following. Copy readWriteImages.cpp to a folder somewhere and type
  • g++ `Magick++-config --cxxflags --cppflags` -o readWriteImages readWriteImages.cpp `Magick++-config --ldflags --libs`
Does that build / execute for you? Works for us of course.
mixersoft
Posts: 6
Joined: 2008-05-08T16:36:10-07:00

Re: newbie needs help compiling a simple Magick++ program

Post by mixersoft »

It worked. :D

for those who follow, the problem was as follows:
- installed eclipse & CDT using apt-get
- downloaded Imagemagick source to /path/to/Imagemagick
- tried to config Build to point to Magick++ source. didn't work. :(
- when I ran g++ from the command line, I discoverd that `Magick++-config` could be found in "libmagick++9-dev"
- ran "sudo apt-get install libmagick++9-dev"
- removed all the references to /path/to/Imagemagick because apt-get did everything for me

and voila. it works.
Post Reply