Magick++ with Makefile - no idea what I'm doing.

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
Moschops

Magick++ with Makefile - no idea what I'm doing.

Post by Moschops »

I've got some code I'm writing in OpenSUSE, and I've a need for Magick++.

I installed Magick++ via the YaST software installer, and everything looked good - I have libMagick.a and various .so files etc. tucked away in usr/lib64

So, I added a coulpe of lines of code to test the Magick++, and am confronted with errors like this:

Code: Select all

(.text+0x79f): undefined reference to `AcquireImagePixels'
/usr/lib64/libMagick++.a(Image.o): In function `Magick::Image::getConstPixels(int, int, unsigned int, unsigned int) const':
(.text+0x7b2): undefined reference to `DestroyExceptionInfo'
/usr/lib64/libMagick++.a(Image.o): In function `Magick::Image::type() const':
Lots and lots of these. So, makes me think I must be not linking to a needed Magick++ library or the like. To a large extent, I don't really know what I'm doing when it comes to linking to libraries using a Makefile. This is the first one I've done. We all start somewhere, I suppose. The line in my makefile where I try to link to the library is as follows:

Code: Select all

rec: hardware/rec.c audio_utils.o utils.o
        g++ $(FLAGS) -I. $(HARDWARE_INCLUDE) hardware/rec.c  /usr/lib64/libMagick++.a audio_utils.o utils.o $(HARDWARE_LIB) -lpthread -o rec
Can anyone explain what's going wrong to produce these error messages, and whether I'm doing the right sort of thing in the Makefile?


Edit: Eventually changed the Makefile line to read as follows:

Code: Select all

rec: hardware/rec.c audio_utils.o utils.o
        g++ $(FLAGS) -I. $(HARDWARE_INCLUDE) `Magick++-config --cxxflags --cppflags --ldflags --libs` hardware/rec.c  /usr/lib64/libMagick++.a audio_utils.o utils.o $(HARDWARE_LIB) -lpthread -o record
All seemed good for a while, until the following lines of code

Code: Select all

Image Mimage();
Mimage.read("testout.png");
gave the error

Code: Select all

hardware/rec.c:122: error: expected constructor, destructor, or type conversion before ‘.’ token
No error about creating an object of type Image, so it seems that something is going right, but then this error when I try to use the read function of that type (or any other function of that type).
Last edited by Moschops on 2008-07-11T05:05:35-07:00, edited 1 time in total.
entropy

Re: Magick++ with Makefile - no idea what I'm doing.

Post by entropy »

Looks to me like you're only linking Magick++, but not the Magick-Libraries it depends on.

Use the Magick++-config utilitity to find out the right parameters to pass to gcc:

Code: Select all

     g++ $(FLAGS) -I. $(HARDWARE_INCLUDE) `Magick++-config --cppflags --cxxflags --ldflags --libs` hardware/rec.c audio_utils.o utils.o $(HARDWARE_LIB) -lpthread -o rec
`Magick++-config --cppflags --cxxflags --ldflags --libs`
expands to:

Code: Select all

-I/usr/include/ImageMagick
-march=k8 -mtune=athlon64 -O2 -pipe -Wall -W -pthread
-L/usr/lib64 -L/usr/lib64 -lfreetype -lz
-L/usr/lib64 -lMagick++ -lMagickWand -lMagickCore
on my machine.
Moschops

Re: Magick++ with Makefile - no idea what I'm doing.

Post by Moschops »

Many thanks for this, slowly getting somewhere... any ideas about my next problem (edited into the first post)?

The command Magick++-config --cppflags --cxxflags --ldflags --libs give me the following result:

-I/usr/include
-O2 -fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -g -Wall -W -pthread
-L/usr/lib64 -L/usr/lib64 -L/usr/lib64 -lfreetype -lz -L/usr/lib
-lMagick++ -lMagick -llcms -ltiff -lfreetype -ljpeg -lfontconfig -lexpat -lXext -lSM -lICE -lX11 -lXt -lbz2 -lz -lpthread -lm -lpthread -lWand -lMagick


So, my complete makefile command for this looks like this (a bit of a mess, really):

rec: hardware/rec.c audio_utils.o utils.o
g++ $(FLAGS) -I. $(HARDWARE_INCLUDE) -I/usr/include
-O2 -fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -g -Wall -W -pthread
-L/usr/lib64 -L/usr/lib64 -L/usr/lib64 -lfreetype -lz -L/usr/lib
-lMagick++ -lMagick -llcms -ltiff -lfreetype -ljpeg -lfontconfig -lexpat -lXext -lSM -lICE -lX11 -lXt -lbz2 -lz -lpthread -lm -lpthread -lWand -lMagick hardware/rec.c /usr/lib64/libMagick++.a audio_utils.o utils.o $(HARDWARE_LIB) -lpthread -o record

I'm reaching the limits of my knowledge here... could some problem in this g++ command cause the problem with Image::read(const string& filename) as in my post above?

$FLAGS gives me:

-Wall -g -DDEBUG -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -O3 -mmmx -msse2

I wish I knew more about this. Could there be some conflict between the settings from FLAGS and the Magick++-config parts?
Post Reply