unable to run wand.c

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
bagi

unable to run wand.c

Post by bagi »

I am using ImageMagick-6.3.7-Q16(6.3.7.8 installable) and VC6 for compiling the C code "wand.c" available in www/magick-wand.html.

#include <stdio.h>
#include <stdlib.h>
#include <wand/MagickWand.h>

int main(int argc,char **argv)
{
#define ThrowWandException(wand) \
{ \
char \
*description; \
\
ExceptionType \
severity; \
\
description=MagickGetException(wand,&severity); \
(void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \
description=(char *) MagickRelinquishMemory(description); \
exit(-1); \
}

MagickBooleanType
status;

MagickWand
*magick_wand;

if (argc != 3)
{
(void) fprintf(stdout,"Usage: %s image thumbnail\n",argv[0]);
exit(0);
}
/*
Read an image.
*/
MagickWandGenesis();
magick_wand=NewMagickWand();
status=MagickReadImage(magick_wand,argv[1]);
if (status == MagickFalse)
ThrowWandException(magick_wand);
/*
Turn the images into a thumbnail sequence.
*/
MagickResetIterator(magick_wand);
while (MagickNextImage(magick_wand) != MagickFalse)
MagickResizeImage(magick_wand,106,80,LanczosFilter,1.0);
/*
Write the image then destroy it.
*/
status=MagickWriteImages(magick_wand,argv[2],MagickTrue);
if (status == MagickFalse)
ThrowWandException(magick_wand);
magick_wand=DestroyMagickWand(magick_wand);
MagickWandTerminus();
return(0);
}

After including the include/magick, include/magick++, include/wand, include, lib as additional include libraries also i am unable to build the code. please there are no compilation errors.

Linking...
temp.obj : error LNK2001: unresolved external symbol _MagickWandTerminus
temp.obj : error LNK2001: unresolved external symbol _DestroyMagickWand
temp.obj : error LNK2001: unresolved external symbol _MagickWriteImages
temp.obj : error LNK2001: unresolved external symbol _MagickResizeImage
temp.obj : error LNK2001: unresolved external symbol _MagickNextImage
temp.obj : error LNK2001: unresolved external symbol _MagickResetIterator
temp.obj : error LNK2001: unresolved external symbol _MagickRelinquishMemory
temp.obj : error LNK2001: unresolved external symbol _MagickGetException
temp.obj : error LNK2001: unresolved external symbol _MagickReadImage
temp.obj : error LNK2001: unresolved external symbol _NewMagickWand
temp.obj : error LNK2001: unresolved external symbol _MagickWandGenesis
Debug/temp.exe : fatal error LNK1120: 11 unresolved externals
Error executing link.exe.

temp.exe - 12 error(s), 0 warning(s)

the Magick++_Demo.dsw could be build but on running it crashes without producing any output file.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: unable to run wand.c

Post by magick »

You need to link to the Wand library. We don't have VS 6 so we cannot explain the crash you are getting. We tried with VS 7 and the Magick++ demos ran without complaint.
bagi

Re: unable to run wand.c

Post by bagi »

The code that I am running now:

#include <stdio.h>
#include <stdlib.h>
#include <wand/MagickWand.h>

int main(int argc,char **argv)
{
#define ThrowWandException(wand)
{
char *description;

ExceptionType severity;

description = MagickGetException(wand, &severity);
(void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description);
description = MagickRelinquishMemory(description);
exit(-1);
}

MagickBooleanType status;

MagickWand *magick_wand;

if (argc != 3)
{
(void) fprintf(stdout,"Usage: %s image thumbnail\n",argv[0]);
exit(0);
}

/* Read an image. */
MagickWandGenesis();
magick_wand = NewMagickWand();
status = MagickReadImage(magick_wand,argv[1]);
if (status == MagickFalse)
ThrowWandException(magick_wand);

/* Turn the images into a thumbnail sequence. */
MagickResetIterator(magick_wand);
while (MagickNextImage(magick_wand) != MagickFalse)
MagickResizeImage(magick_wand,106,80,LanczosFilter,1.0);

/* Write the image then destroy it. */
status = MagickWriteImages(magick_wand,argv[2],MagickTrue);
if (status == MagickFalse)
ThrowWandException(magick_wand);
magick_wand = DestroyMagickWand(magick_wand);
MagickWandTerminus();
return(0);
}

Additional Include Directories: (Microsoft Visual C++ 6.0)
C:\Program Files\ImageMagick-6.3.7-Q16\include,
C:\Program Files\ImageMagick-6.3.7-Q16\lib


The compilation errors which I get

Compiling...
Text1.c
C:\Program Files\Microsoft Visual Studio\MyProjects\Text1.c(13) : error C2065: 'wand' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\Text1.c(13) : warning C4047: 'function' : 'const struct _MagickWand *' differs in levels of indirection from 'int '
C:\Program Files\Microsoft Visual Studio\MyProjects\Text1.c(13) : warning C4024: 'MagickGetException' : different types for formal and actual parameter 1
C:\Program Files\Microsoft Visual Studio\MyProjects\Text1.c(19) : error C2275: 'MagickBooleanType' : illegal use of this type as an expression
c:\program files\imagemagick-6.3.7-q16\include\magick\magick-type.h(168) : see declaration of 'MagickBooleanType'
C:\Program Files\Microsoft Visual Studio\MyProjects\Text1.c(19) : error C2146: syntax error : missing ';' before identifier 'status'
C:\Program Files\Microsoft Visual Studio\MyProjects\Text1.c(19) : error C2065: 'status' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\Text1.c(21) : error C2275: 'MagickWand' : illegal use of this type as an expression
c:\program files\imagemagick-6.3.7-q16\include\wand\magickwand.h(136) : see declaration of 'MagickWand'
C:\Program Files\Microsoft Visual Studio\MyProjects\Text1.c(21) : error C2065: 'magick_wand' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\Text1.c(31) : warning C4047: '=' : 'int ' differs in levels of indirection from 'struct _MagickWand *'
C:\Program Files\Microsoft Visual Studio\MyProjects\Text1.c(32) : warning C4047: 'function' : 'struct _MagickWand *' differs in levels of indirection from 'int '
C:\Program Files\Microsoft Visual Studio\MyProjects\Text1.c(32) : warning C4024: 'MagickReadImage' : different types for formal and actual parameter 1
C:\Program Files\Microsoft Visual Studio\MyProjects\Text1.c(37) : warning C4047: 'function' : 'struct _MagickWand *' differs in levels of indirection from 'int '
C:\Program Files\Microsoft Visual Studio\MyProjects\Text1.c(37) : warning C4024: 'MagickResetIterator' : different types for formal and actual parameter 1
C:\Program Files\Microsoft Visual Studio\MyProjects\Text1.c(38) : warning C4047: 'function' : 'struct _MagickWand *' differs in levels of indirection from 'int '
C:\Program Files\Microsoft Visual Studio\MyProjects\Text1.c(38) : warning C4024: 'MagickNextImage' : different types for formal and actual parameter 1
C:\Program Files\Microsoft Visual Studio\MyProjects\Text1.c(39) : warning C4047: 'function' : 'struct _MagickWand *' differs in levels of indirection from 'int '
C:\Program Files\Microsoft Visual Studio\MyProjects\Text1.c(39) : warning C4024: 'MagickResizeImage' : different types for formal and actual parameter 1
C:\Program Files\Microsoft Visual Studio\MyProjects\Text1.c(42) : warning C4047: 'function' : 'struct _MagickWand *' differs in levels of indirection from 'int '
C:\Program Files\Microsoft Visual Studio\MyProjects\Text1.c(42) : warning C4024: 'MagickWriteImages' : different types for formal and actual parameter 1
C:\Program Files\Microsoft Visual Studio\MyProjects\Text1.c(45) : warning C4047: 'function' : 'struct _MagickWand *' differs in levels of indirection from 'int '
C:\Program Files\Microsoft Visual Studio\MyProjects\Text1.c(45) : warning C4024: 'DestroyMagickWand' : different types for formal and actual parameter 1
C:\Program Files\Microsoft Visual Studio\MyProjects\Text1.c(45) : warning C4047: '=' : 'int ' differs in levels of indirection from 'struct _MagickWand *'
Error executing cl.exe.

Text1.obj - 6 error(s), 16 warning(s)
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: unable to run wand.c

Post by magick »

C defines require a backslash for line continuation. See your ThrowWandException macro.
bagi

Re: unable to run wand.c

Post by bagi »

Thanks, that removed all the errors and I could run the file :D

The only thing now remaining is i am unable to understand the arguments in int main(int argc, char **argv )

The output is Usage: C:\Program Files\Microsoft Visual Studio\MyProjects\Debug\Temp1.exe image thumbnail

how do i give a file as an input and get the output?
bagi

Re: unable to run wand.c

Post by bagi »

I could figure it out, Thanks!!! :D
stotro

Re: unable to run wand.c

Post by stotro »

sorry for digging this out, but i have not the same, but a similiar problem:

Code: Select all

#include "main.h"

#include <stdio.h>
#include <stdlib.h>
#include <wand/MagickWand.h>



int main()
{
	start();
	#define ThrowWandException(wand) \
{ \
  char \
    *description; \
 \
  ExceptionType \
    severity; \
 \
  description=MagickGetException(wand,&severity); \
  (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \
  description=(char *) MagickRelinquishMemory(description); \
  exit(-1); \
}
	MagickWand *test;

	return 0;
}
1>.\main.c(29) : error C2275: 'MagickWand' : illegal use of this type as an expression
1> C:\ImageMagick\include\wand/MagickWand.h(144) : see declaration of 'MagickWand'
1>.\main.c(29) : error C2065: 'test' : undeclared identifier
i think the library is working because it doesn throw up any errors for the include & the exception definition..
any suggestions?

thanks
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: unable to run wand.c

Post by magick »

We tried your code with ImageMagick 6.4.4-5, the latest release and it compiled without complaint (when we included a mock main() method). Its possible your version of ImageMagick is too old to support the MagickWand API.
stotro

Re: unable to run wand.c

Post by stotro »

i solved the problem. i was using the newest version anyway, but the type of my visual studio project wasnt declared als multi threaded dll..
now it works fine.
Post Reply