Magick++ and Debian

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
NearlyALaugh

Magick++ and Debian

Post by NearlyALaugh »

Hi!

I'm running Debian Etch and I installed ImageMagick from source following the (*nix) instructions here: http://www.imagemagick.org/script/insta ... e.php#unix

What steps do I need to follow to get the g++ compiler to include the Magick++ files?

g++ returns the following errors when I try to compile a file that includes Magick++.h:

Code: Select all

/usr/local/include/ImageMagick/Magick++.h:9:30: error: Magick++/Include.h: No such file or directory
/usr/local/include/ImageMagick/Magick++.h:10:28: error: Magick++/Image.h: No such file or directory
/usr/local/include/ImageMagick/Magick++.h:11:29: error: Magick++/Pixels.h: No such file or directory
/usr/local/include/ImageMagick/Magick++.h:12:26: error: Magick++/STL.h: No such file or directory
The file /usr/local/include/ImageMagick/Magick++.h includes the relative path names of those files, but those aren't recognized. Making the pathnames absolute (thus adding "/usr/local/include/ImageMagick/" to each filename) fixes these errors, but generates more errors as the included files try to include relative paths of their own.

For simplicity's sake, the C++ file I'm trying to compile contains just one line:

Code: Select all

#include </usr/local/include/ImageMagick/Magick++.h>
I specified the absolute pathname because Magick++.h is not to be found in /usr/include/ (I know I could probably create a link to it once it works).

Thank you very much,

Peace~
NearlyALaugh

Re: Magick++ and Debian

Post by NearlyALaugh »

I realize this may be a g++ problem rather than an ImageMagick problem; if so, I'll gladly ask elsewhere.

Thanks~
NearlyALaugh

Re: Magick++ and Debian

Post by NearlyALaugh »

Turns out, like with most things, it was neither Magick++'s nor g++'s problem: it was mine!

Using

Code: Select all

-I/usr/local/include/ImageMagick
in my command fixed the problem. I tried that before, I thought... but no matter!

Thanks :roll: :oops:
NearlyALaugh

Re: Magick++ and Debian

Post by NearlyALaugh »

I guess I was too quick to proclaim success. All the necessary files appear to be included, but I don't know what to make of the errors I get when trying to build this simple code based on an example in the documentation:

Code: Select all

#include <iostream>
#include <Magick++.h>
using namespace Magick;
using namespace std;

int main(int argc,char** argv) {
	Image image;
	
	image.read("~/logo.gif");
	image.crop(Geometry(100,100,100,100));
	image.write("~/logo_cropped.gif");
	return 0;
}
I can compile the code, but linking it gives the following errors:

Code: Select all

/tmp/ccV7ZYjZ.o: In function `main':
magickplusplus.cpp:(.text+0x8b): undefined reference to `Magick::Image::Image()'magickplusplus.cpp:(.text+0xc2): undefined reference to `Magick::Image::read(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
magickplusplus.cpp:(.text+0x12b): undefined reference to `Magick::Geometry::Geometry(unsigned int, unsigned int, unsigned int, unsigned int, bool, bool)'
magickplusplus.cpp:(.text+0x158): undefined reference to `Magick::Image::crop(Magick::Geometry const&)'
magickplusplus.cpp:(.text+0x163): undefined reference to `Magick::Geometry::~Geometry()'
magickplusplus.cpp:(.text+0x176): undefined reference to `Magick::Geometry::~Geometry()'
magickplusplus.cpp:(.text+0x1b5): undefined reference to `Magick::Image::write(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
magickplusplus.cpp:(.text+0x1f3): undefined reference to `Magick::Image::~Image()'
magickplusplus.cpp:(.text+0x21f): undefined reference to `Magick::Image::~Image()'
collect2: ld returned 1 exit status
The g++ command in question is this:

Code: Select all

g++ -Wall "magickplusplus.cpp" -I/usr/local/include/ImageMagick/ -o magickplusplus
Thoughts?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Magick++ and Debian

Post by magick »

Compile your source module with this command:
  • g++ `Magick++-config --cxxflags --cppflags` -o magick++ magick++.cpp `Magick++-config --ldflags --libs`
NearlyALaugh

Re: Magick++ and Debian

Post by NearlyALaugh »

Thank you very much; I am just learning C++, and thus didn't understand the importance of that command when I read it in the documentation. I had to create symbolic links in /usr/lib/ to be able to run the program, though. Below are the steps that fixed the problem in case anyone else has the same issue.

Creating symbolic links:

Code: Select all

$ sudo ln -s /usr/local/lib/libMagickWand.so.1 /usr/lib/libMagickWand.so.1
$ sudo ln -s /usr/local/lib/libMagickCore.so.1 /usr/lib/libMagickCore.so.1
To compile:

Code: Select all

$ g++ `Magick++-config --cxxflags --cppflags --ldflags --libs` somefile.cpp -o somefile
And now I have a beautiful cropped image of the ImageMagick logo!

Image

Well... sort of. Now to learn how to use Magick++... :roll:

In any case, thanks again. :D
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Magick++ and Debian

Post by el_supremo »

FYI: the GIF image format has a "virtual canvas" concept so that when you crop (or trim) an image and save it as a GIF, if you don't reset the virtual canvas you usually end up with the original image or at least an odd looking one as in your example.
Two ways around it.
Save the file as PNG or JPG instead - they don't have a virtual canvas.
Add this statement to force a reset of the canvas before writing the GIF:

Code: Select all

image.page("0x0+0+0");

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
NearlyALaugh

Re: Magick++ and Debian

Post by NearlyALaugh »

Thanks -- I was wondering why that came out sorta weird!
NearlyALaugh

Re: Magick++ and [Windows]

Post by NearlyALaugh »

I have one more question, this time regarding use with Windows [XP]. I installed ImageMagick without a problem using the automated installer, but as with my Linux installation, the compiler doesn't find Magick++.h.

Code: Select all

Magick++.h: No such file or directory
I'm using the Dev-C++ IDE which itself uses g++/MingW as its compiler. Do the steps above have counterparts that apply to Windows?

Any suggestions would be appreciated! Thanks in advance~

---
Edit: On the second-to-last page of a forum search for "windows install", I came across a helpful post by el_supremo:
el_supremo wrote:[Y]ou have to point the compiler at the include and lib directories. This will depend upon the compiler/IDE you are using. . . . but the steps are probably similar anyway:
Right click on the project name and select Properties and then modify the following options:
- In C/C++|General: In "Additional Include Directories" add the path to your include directory - something like "C:\Program Files\ImageMagick-6.3.0-Q16\include"
- In Linker|General: Add the additional library directory C:\Program Files\ImageMagick-6.3.0-Q16\lib
- In Linker|Input: Add the Additional Dependencies CORE_RL_magick_.lib CORE_RL_wand_.lib CORE_RL_Magick++_.lib
Adding the include and lib directories, along with including Magick++.h at the top of my C++ source (above iostream and the rest), fixed the missing file errors.

I'm still getting one error however, which may or may not be connected to the third step above which I couldn't figure out how to implement. Here is the full compiler log through Dev-C++:

Code: Select all

Executing g++.exe...
g++.exe "C:\Documents and Settings\taylor\Desktop\Programming\magickplusplus.cpp." -o "C:\Documents and Settings\taylor\Desktop\Programming\magickplusplus.exe" -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -I"C:\Program Files\ImageMagick-6.4.7-Q16\include" -L"C:\Dev-Cpp\lib" -L"C:\Program Files\ImageMagick-6.4.7-Q16\lib"
In file included from C:/Dev-Cpp/include/stdio.h:399,
        from C:/Program Files/ImageMagick-6.4.7-Q16/include/Magick++/Include.h:22,
        from C:/Program Files/ImageMagick-6.4.7-Q16/include/Magick++.h:9,
        from C:\Documents and Settings\taylor\Desktop\Programming\magickplusplus.cpp:1:
C:/Dev-Cpp/include/sys/types.h:104: error: redeclaration of C++ built-in type `long'
Execution terminated
Thanks for taking the time to help.
NearlyALaugh

Re: Magick++ and Debian

Post by NearlyALaugh »

Hi, again. Any insights?

Thanks and happy new year!
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Magick++ and Debian

Post by el_supremo »

Sometimes you can get that sort of compiler error either because you are including (-I) more files than you need or because they are in the wrong order.
But, since the compiler is complaining about line 104 in C:/Dev-Cpp/include/sys/types.h, have a look at line 104 in that file and the lines which preceded it. There may be an #ifdef or #ifndef a few lines in front of it which is causing it to try to override the definition of "long".

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
Post Reply