linkage problems with Magick++ and MinGW

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
neuviemep

linkage problems with Magick++ and MinGW

Post by neuviemep »

Hi there,

I'm developing a C++ program using Magick++ in Linux. Up till now everything has been working great, but I've hit a wall while trying to build a Windows port using MinGW. To illustrate the problem, let's say we have a simple program:

Code: Select all

int main(int argc, char **argv)
{
#ifdef WIN32
	InitializeMagick(*argv);
#endif
	Image pic;
	pic.read("a.bmp");
	pic.crop( Geometry(100,100, 100, 100));
	pic.write("b.bmp");
}
This compiles and links without a problem in Linux. Next, I've installed a binary Windows release of IM, but I can't get even such a simple program to link successfully with the CORE_RL* dll's.

Code: Select all

neuviemep@ihuarraquax:magick$ i586-mingw32msvc-g++ -I/mnt/winxp/Program\ Files/ImageMagick-6.3.7-Q16/include/ -o mtest.exe mtest.cc -L/mnt/winxp/Program\ Files/ImageMagick-6.3.7-Q16/ -lCORE_RL_Magick++_
undefined reference to `Magick::Image::Image()'
undefined reference to Magick::Image::read(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
[...]
collect2: ld returned 1 exit status
I get the exact same results while trying to compile with MinGW in Windows. I'd be very grateful for any helpful suggestions. Thanks.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: linkage problems with Magick++ and MinGW

Post by magick »

Under MSYS we configured / built / installed ImageMagick-6.5.1-0. Next we created magick++.cpp as

Code: Select all

#include <Magick++.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>

using namespace std;
using namespace Magick;

int main(int argc, char **argv)
{
   Image pic;
   pic.read("a.bmp");
   pic.crop( Geometry(100,100, 100, 100));
   pic.write("b.bmp");
}
Finally we compile magick++.cpp like this:
  • g++ `Magick++-config --cxxflags --cppflags` -o magick++ magick++.cpp `Magick++-config --ldflags --libs`
This links and runs without complaint.
neuviemep

Re: linkage problems with Magick++ and MinGW

Post by neuviemep »

magick wrote: Under MSYS we configured / built / installed ImageMagick-6.5.1-0.
[....]
This links and runs without complaint.
Which is to say, I guess, if anyone else be wondering, that one needs a MinGW-compiled version of ImageMagick in order to compile IM-utilizing programs using MinGW - the binary Windows installation DLLs won't work because they've been built using MSVC, and there seem to exist some issues with linking to MSVC-built libraries with MinGW. Did I get this right?

Reportedly, there are ways to fashion a MinGW-usable DLL from a MSVC DLL using the tools reimp/pexports, dlltool, but I guess I'll try this approach, looks cleaner.

Thanks.
Post Reply