Page 1 of 1
Magick++ and Debian
Posted: 2008-12-17T22:02:01-07:00
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~
Re: Magick++ and Debian
Posted: 2008-12-18T13:17:53-07:00
by NearlyALaugh
I realize this may be a g++ problem rather than an ImageMagick problem; if so, I'll gladly ask elsewhere.
Thanks~
Re: Magick++ and Debian
Posted: 2008-12-19T10:37:54-07:00
by NearlyALaugh
Turns out, like with most things, it was neither Magick++'s nor g++'s problem: it was mine!
Using
in my command fixed the problem. I tried that before, I thought... but no matter!
Thanks
Re: Magick++ and Debian
Posted: 2008-12-19T11:14:32-07:00
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?
Re: Magick++ and Debian
Posted: 2008-12-19T11:42:51-07:00
by magick
Compile your source module with this command:
- g++ `Magick++-config --cxxflags --cppflags` -o magick++ magick++.cpp `Magick++-config --ldflags --libs`
Re: Magick++ and Debian
Posted: 2008-12-19T15:35:08-07:00
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!
Well... sort of. Now to learn how to use Magick++...
In any case, thanks again.
Re: Magick++ and Debian
Posted: 2008-12-19T17:11:53-07:00
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:
Pete
Re: Magick++ and Debian
Posted: 2008-12-19T17:16:57-07:00
by NearlyALaugh
Thanks -- I was wondering why that came out sorta weird!
Re: Magick++ and [Windows]
Posted: 2008-12-21T16:11:13-07:00
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.
Re: Magick++ and Debian
Posted: 2008-12-30T23:58:17-07:00
by NearlyALaugh
Hi, again. Any insights?
Thanks and happy new year!
Re: Magick++ and Debian
Posted: 2008-12-31T10:08:17-07:00
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