Compile and linker problems: help

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
erotavlas_turbo

Compile and linker problems: help

Post by erotavlas_turbo »

Hi,

I have written this C code that work well as stand-alone software. I'm trying to integrate it on a preexisting software, but without success.

The code is the following

Code: Select all

void DrawText(char *inputImage, char *outputImage, char *outputFormat, char *conferenceName, char *data, char *userName, char *userID) {

	MagickBooleanType status;
    MagickWand *magick_wand = NULL;
    DrawingWand *d_wand = NULL;
    PixelWand *p_wand = NULL;

  [b]  magick_wand = NewMagickWand();[/b]
    d_wand = NewDrawingWand();
    p_wand = NewPixelWand();

	// fixed data
	char *user = "Utente";
	char *ID = "ID";

	// initialize MagickWand environment
	MagickWandGenesis();
	
    // Read the image. 
    status = MagickReadImage(magick_wand, inputImage);
	if (status == MagickFalse) {
		printf("Unable to Read\n");
		//ThrowWandException(magick_wand);
	}
    
	// Scale the image dimension
	if (strcmp(outputFormat,"CIF") == 0) 
		status = MagickScaleImage(magick_wand, 352, 288);
	else if (strcmp(outputFormat,"QCIF") == 0) 
		status = MagickScaleImage(magick_wand, 176, 144);
	else 
		printf("Invalid output format %s\n", outputFormat);

	if (status == MagickFalse) {
		printf("Unable to Scale\n");
		//ThrowWandException(magick_wand);
	}
		
	// Set up the font size and colour
    DrawSetFont(d_wand,"Helvetica");
    PixelSetColor(p_wand,"black");
    DrawSetFillColor(d_wand,p_wand);
    DrawSetFontSize(d_wand,28);
    // Now draw the text
	DrawAnnotation(d_wand,10,50,(const unsigned char *) conferenceName);

	DrawSetFontSize(d_wand,14);
	DrawAnnotation(d_wand,150,15,(const unsigned char *) data);
    // different font, colour and size
    PixelSetColor(p_wand,"green");
    DrawSetFillColor(d_wand,p_wand);
    DrawSetFontSize(d_wand,20);
    DrawSetFont(d_wand,"Times-Roman");
	// Now draw the text
    DrawAnnotation(d_wand,30,90,(const unsigned char *) user);

    // same size and colour
	DrawSetFont(d_wand,"Times-Roman");
    DrawAnnotation(d_wand,180,90,(const unsigned char *) ID);

    // Draw the image on to the magick_wand
    MagickDrawImage(magick_wand, d_wand);

    // and write it
    status = MagickWriteImage(magick_wand, outputImage);

    /* Clean up */
    if (status == MagickFalse)
		//ThrowWandException(magick_wand);
    if(magick_wand) magick_wand = DestroyMagickWand(magick_wand);
    if(d_wand) d_wand = DestroyDrawingWand(d_wand);
    if(p_wand) p_wand = DestroyPixelWand(p_wand);
	
	// terminate the MagickWand environment
	MagickWandTerminus();
	printf("\n%s,%s,%s,%s,%s,%s\n",inputImage, outputImage, conferenceName, data, userName, userID);
}


I have understood that the problem is on the call magick_wand = NewMagickWand() ...If I make the code more simple as the following

Code: Select all

void DrawText(char *inputImage, char *outputImage, char *outputFormat, char *conferenceName, char *data, char *userName, char *userID) {

	MagickBooleanType status;
    MagickWand *magick_wand = NULL;
    DrawingWand *d_wand = NULL;
    PixelWand *p_wand = NULL;
 [b]  magick_wand = NewMagickWand();[/b]



It will work only if I comment the line magick_wand = NewMagickWand() . Probably there is a problem on MagickWand function call. Can you help me?

Thank

NB when i compile the stand-alone code i use the following command cc `MagickWand-config --cflags --cppflags` -o wand wand.c `MagickWand-config --ldflags --libs` that can be simplified as cc -Wall -lMagickWand wand.c -0 wand. when i compile the preexisting software there is a Makefile that define the compilation and linkage parameters.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Compile and linker problems: help

Post by magick »

You have not described that happens when you call NewMagickWand(). Is there a compile or error? If so, what exception is thrown? If its runtime, does the program fail at that line? And if so can you produce a stack trace that we can review?

What version of ImageMagick are you using?
erotavlas_turbo

Re: Compile and linker problems: help

Post by erotavlas_turbo »

Hi,

I have solved :D ...The problem is in linking stage. I have made a big mistake when i passed the linked parameters...
The linker option -lMagickWand must be passed here

Code: Select all

LIBS = -lMagicWand -lm

$(APP): $(OBJS)
        $(CC) $^ $(LIBS) -o $@

and not here

Code: Select all

CFLAGS +=  -lMagicWand -lm

$(OBJS): $(SOURCE)
        $(CC) $^ $(CFLAGS) -c $(SOURCE)
Post Reply