Page 1 of 1
Assistance with using ImageMagick with MinGW
Posted: 2013-01-09T23:45:30-07:00
by 168gr
Very brief personal background -
I am by no means an experienced or accomplished programmer. I did complete a CS minor as an undergrad (finished ~15 years ago), but went into a non-computer related field. Periodically I've written programs for simple tasks or my own entertainment. These days I would say I'm on the edge of functional literacy with C and unix. I last used ImageMagick on Linux in 2001 or 2002. It's a little different now. Apologies if some of these questions are annoyingly basic ... I think I just need some memory jogging.
Presently I'm working on a simple win32 program that needs to do some very basic image processing and display. The MagickWand API looks great. I'm working on a Windows 7 laptop with the MinGW 1.1 compiler.
From searching this forum, it appears that the binary distributions are incompatible with MinGW. I've downloaded ImageMagick-6.8.1-9, unpacked it, all the source is there. From what I can discern from the included docs, the expectation is that people are using Visual Studio (or maybe Borland).
Can someone point me in the right direction for getting ImageMagick built on Windows with MinGW? I don't see a makefile for mingw32-make, and I don't know what (if anything) I need to do with the configure scripts. Additional libraries I need to acquire? Anything special to link the ImageMagick stuff to my as-yet trivially simple 'hello world' win32 program?
I think if I can get a simple win32 program that includes
this basic MagickWand routine to compile and run, I can take it from there.
Thank you.
Re: Assistance with using ImageMagick with MinGW
Posted: 2013-01-10T02:08:34-07:00
by 168gr
Problem #1 solved. Shook a little rust of my brain, and using a msys shell, I could run ./configure and then make. MinGW built ImageMagick without complaint.
Problem #2 is probably equally trivial ... I realize this isn't really an ImageMagick-specific issue but a makefile/linking issue.
Here's the error:
Code: Select all
gcc -o "testprogram.exe" obj/winmain.o obj/callbacks.o obj/resource.o -s -lcomctl32 -Wl,--subsystem,windows
obj/callbacks.o:callbacks.c:(.text+0x55): undefined reference to `MagickWandGenesis'
obj/callbacks.o:callbacks.c:(.text+0x5a): undefined reference to `NewMagickWand'
obj/callbacks.o:callbacks.c:(.text+0x6c): undefined reference to `MagickReadImage'
obj/callbacks.o:callbacks.c:(.text+0x7c): undefined reference to `MagickWriteImage'
obj/callbacks.o:callbacks.c:(.text+0x88): undefined reference to `DestroyMagickWand'
obj/callbacks.o:callbacks.c:(.text+0x91): undefined reference to `MagickWandTerminus'
collect2: ld returned 1 exit status
mingw32-make: *** [testprogram.exe] Error 1
What linking option do I need to put in there to get this to build?
Here's the makefile. (Test program is a simple do-nothing win32 prorgam from
this tutorial; it's their example makefile.) I plopped the 'magick' and 'wand' directories in the 'include' directory so the compiler could find them. Not sure if this is the correct/favored way to do it, but it allowed the thing to compile without issue. Linking is the problem.
Code: Select all
HEADERS = include/callbacks.h include/resource.h
OBJS = obj/winmain.o obj/callbacks.o obj/resource.o
INCLUDE_DIRS = -I.\include
WARNS = -Wall
CC = gcc
CFLAGS = -O3 -std=c99 -D UNICODE -D _UNICODE -D _WIN32_IE=0x0500 -D WINVER=0x500 ${WARNS}
LDFLAGS = -s -lcomctl32 -Wl,--subsystem,windows
RC = windres
all : testprogram.exe
testprogram.exe : ${OBJS}
${CC} -o "$@" ${OBJS} ${LDFLAGS}
clean :
del obj\*.o "testprogram.exe"
obj/%.o : src/%.c ${HEADERS}
${CC} ${CFLAGS} ${INCLUDE_DIRS} -c $< -o $@
obj/resource.o : res/resource.rc res/Application.manifest res/Application.ico include/resource.h
${RC} -I.\include -I.\res -i $< -o $@
Thank you.
Re: Assistance with using ImageMagick with MinGW
Posted: 2013-01-10T05:27:02-07:00
by magick
Type
- MagickWand-config --cflags --cppflags
to display the expected compile flags to build custom code for MagickWand. Type
- MagickWand-config --ldflags --libs
to display the loader flags.
Re: Assistance with using ImageMagick with MinGW
Posted: 2013-01-10T10:37:11-07:00
by 168gr
Thank you -
For some reason pkg-config isn't part of the MinGW install.
Code: Select all
$ ./MagickWand-config --cflags --cppflags
./MagickWand-config: line 41: pkg-config: command not found
./MagickWand-config: line 47: pkg-config: command not found
$ ./MagickWand-config --ldflags --libs
./MagickWand-config: line 50: pkg-config: command not found
./MagickWand-config: line 53: pkg-config: command not found
After getting the GTK+ runtime from
http://sourceforge.net/projects/gimp-win/files/ and pkg-config.exe from
http://www.gtk.org/download/win32.php ...
Code: Select all
$ ./MagickWand-config --cflags
Package MagickWand was not found in the pkg-config search path.
Perhaps you should add the directory containing `MagickWand.pc'
to the PKG_CONFIG_PATH environment variable
No package 'MagickWand' found
$ echo $PKG_CONFIG_PATH
~/project/ImageMagick-6.8.1-9/wand
Not sure why it was complaining. So after screwing around with pkg-config.exe for a while, I re-ran the ImageMagick configure script, and at the end it printed this helpful bit
Code: Select all
Options used to compile and link:
PREFIX = /usr/local
EXEC-PREFIX = /usr/local
VERSION = 6.8.1
CC = gcc -std=gnu99 -std=gnu99
CFLAGS = -fopenmp -g -O2 -Wall -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16
CPPFLAGS = -I/usr/local/include/ImageMagick -D_DLL -D_MT
PCFLAGS = -fopenmp -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16 -D_DLL -D_MT
DEFS = -DHAVE_CONFIG_H
LDFLAGS =
MAGICK_LDFLAGS = -L/usr/local/lib
LIBS = -lMagickCore -lgdi32 -lm -lgomp -lpthread
CXX = g++
CXXFLAGS = -g -O2
FEATURES = OpenMP
DELEGATES = ps
Great, so now the Makefile reads
Code: Select all
HEADERS = include/callbacks.h include/resource.h
OBJS = obj/winmain.o obj/callbacks.o obj/resource.o
INCLUDE_DIRS = -I.\include
WARNS = -Wall
CC = gcc
CFLAGS = -O3 -std=c99 -D UNICODE -D _UNICODE -D _WIN32_IE=0x0500 -D WINVER=0x500 ${WARNS} -fopenmp -g -O2 -Wall -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16
LDFLAGS = -s -lcomctl32 -Wl,--subsystem,windows
RC = windres
LIBS = -lMagickCore -lgdi32 -lm -lgomp -lpthread
all : testprogram.exe
testprogram.exe : ${OBJS}
${CC} -o "$@" ${OBJS} ${LDFLAGS} ${LIBS}
clean :
del obj\*.o "testprogram.exe"
obj/%.o : src/%.c ${HEADERS}
${CC} ${CFLAGS} ${INCLUDE_DIRS} -c $< -o $@
obj/resource.o : res/resource.rc res/Application.manifest res/Application.ico include/resource.h
${RC} -I.\include -I.\res -i $< -o $@
And an attempted make got me this error
Code: Select all
$ make
gcc -o "testprogram.exe" obj/winmain.o obj/callbacks.o obj/resource.o -s -lcomctl32 -Wl,--subsystem,windows -lMagickCore -lgdi32 -lm -lgomp -lpthread
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lMagickCore
collect2: ld returned 1 exit status
make: *** [testprogram.exe] Error 1
What next? How do I tell the compiler where to find lMagickCore? Where should it be?
Thanks.
Re: Assistance with using ImageMagick with MinGW
Posted: 2013-01-10T10:46:02-07:00
by magick
Try -lMagickCore-Q16.
Re: Assistance with using ImageMagick with MinGW
Posted: 2013-01-10T11:44:42-07:00
by 168gr
magick wrote:Try -lMagickCore-Q16.
No luck, same error.
Re: Assistance with using ImageMagick with MinGW
Posted: 2013-01-10T11:45:25-07:00
by magick
If you compiled ImageMagick and installed it, all libraries should by default be in /usr/local/lib. Take a look. Is there a libMagickCore-Q16.a? If so, -L/usr/local/lib -lMagickCore-Q16 should work.
Re: Assistance with using ImageMagick with MinGW
Posted: 2013-01-10T12:01:29-07:00
by 168gr
Made a little progress ...
Changed the line in the Makefile to
Code: Select all
LIBS = -lMagickCore-Q16 -lMagickWand-Q16 -lgdi32 -lm -lgomp -lpthread
and manually copied two files:
- libMagickCore-Q16.a
- libMagickWand-Q16.a
to the c:\mingw\lib directory.
Now the compiler gets verbosely angry
Code: Select all
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../libMagickWand-Q16.a(wand_libMagickWand_Q16_la-magick-wand.o): In function `ClearMagickWand':
C:\MinGW\msys\1.0\home\pgg\project\ImageMagick-6.8.1-9/wand/magick-wand.c:92: undefined reference to `LogMagickEvent'
C:\MinGW\msys\1.0\home\pgg\project\ImageMagick-6.8.1-9/wand/magick-wand.c:93: undefined reference to `DestroyQuantizeInfo'
C:\MinGW\msys\1.0\home\pgg\project\ImageMagick-6.8.1-9/wand/magick-wand.c:94: undefined reference to `DestroyImageInfo'
C:\MinGW\msys\1.0\home\pgg\project\ImageMagick-6.8.1-9/wand/magick-wand.c:95: undefined reference to `DestroyImageList'
[...]
hundreds of lines of this
[...]
collect2: ld returned 1 exit status
make: *** [testprogram.exe] Error 1
Re: Assistance with using ImageMagick with MinGW
Posted: 2013-01-10T12:22:17-07:00
by magick
Try -lMagickWand-Q16 -lMagickCore-Q16.
Re: Assistance with using ImageMagick with MinGW
Posted: 2013-01-10T12:35:09-07:00
by 168gr
magick wrote:If you compiled ImageMagick and installed it, all libraries should by default be in /usr/local/lib. Take a look. Is there a libMagickCore-Q16.a? If so, -L/usr/local/lib -lMagickCore-Q16 should work.
Success ...
Adding -L/usr/local/lib is what did it.
Thanks again for your help. I appreciate your work.
Re: Assistance with using ImageMagick with MinGW
Posted: 2013-01-15T02:09:31-07:00
by broucaries
the usual way to compile to mingw is croscs compile from cygwin see google
Re: Assistance with using ImageMagick with MinGW
Posted: 2013-01-18T08:18:20-07:00
by 168gr
broucaries wrote:the usual way to compile to mingw is croscs compile from cygwin see google
Thank you, I'll give that a try.
Re: Assistance with using ImageMagick with MinGW
Posted: 2013-01-22T01:06:14-07:00
by 168gr
broucaries wrote:the usual way to compile to mingw is croscs compile from cygwin see google
Thanks. I abandoned mingw, installed cygwin, and plopped in the binary distro of ImageMagick for cygwin. It just works. Little 'hello world' win32 program was able to call the ImageMagick routines, so I'm off to do something useful now.
I'm sure I'll be back at some point with ImageMagick specific questions now that I've bludgeoned through the environment, compiler, and linker problems.
Re: Assistance with using ImageMagick with MinGW
Posted: 2016-06-10T11:19:09-07:00
by harry.whitehouse
This thread was very helpful to me but some things have changed with time...
Here's the link statement that works with version 7:
gcc -Wall -fPIC -o "wand" "wand.c" -I /usr/include/ImageMagick/ -L /usr/local/lib -lMagickCore-7.Q16HDRI -lMagickWand-7.Q16HDRI