0

I'm trying to compile my C++ code using Magick++ library to manipulate images in a distributed way using openMPI and I get some errors when I try to compile it.

This is my code:

#include "mpi.h"
#include <stdio.h>
#include <iostream>
#include <Magick++.h>
using namespace std; 
using namespace Magick; 

int main(int argc, char **argv){

int rank, numtask;

InitializeMagick(*argv);

Image image;
try { 
    // Read a file into image object 
    image.read( "test_image.jpg" );
    image.type( GrayscaleType );
    Blob blob; 
    image.magick( "JPEG" ); // Set JPEG output format 
    image.write( &blob );

} 
catch( Exception &error_ ){ 
    cout << "Caught exception: " << error_.what() << endl; 
    return 1; 
 } 

//Now in the "distributed enviroment" I just print an hello world to test it. 
MPI_Init(&argc,&argv);

MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &numtask);

cout<<"HelloWorld\n";

MPI_Finalize();

}

this is the command that I type on the shell

mpiCC openmpi_project.cc -o openmpi_project

and this is the output of the shell

openmpi_project.cc:(.text+0x1d): undefined reference to "Magick::InitializeMagick(char const*)"

openmpi_project.cc:(.text+0x29): undefined reference to "Magick::Image::Image()"

openmpi_project.cc:(.text+0x5d): undefined reference to "Magick::Image::read(std::string const&)"

openmpi_project.cc:(.text+0x86): undefined reference to "Magick::Image::type(MagickCore::ImageType)"

openmpi_project.cc:(.text+0x92): rundefined reference to "Magick::Blob::Blob()"

openmpi_project.cc:(.text+0xc6): undefined reference to "Magick::Image::magick(std::string const&)"

openmpi_project.cc:(.text+0xf1): undefined reference to "Magick::Image::write(Magick::Blob*)"

openmpi_project.cc:(.text+0xfd): undefined reference to "Magick::Blob::~Blob()"

openmpi_project.cc:(.text+0x158): undefined reference to "Magick::Image::~Image()"

openmpi_project.cc:(.text+0x1d3): undefined reference to "Magick::Blob::~Blob()"

openmpi_project.cc:(.text+0x261): undefined reference to "Magick::Image::~Image()"

/tmp/ccqFzUdy.o:(.gcc_except_table+0x58): undefined reference to "typeinfo for Magick::Exception"

3
  • 1
    Did you link to imagemagick? Commented Jan 26, 2015 at 11:42
  • probably not. I installed the ImageMagick.tr.gz following the instructions on the website and then included the library in my project. How can I check it or do it? Commented Jan 26, 2015 at 11:47
  • Duplicate: stackoverflow.com/questions/7330090/magick-linking-error Commented Jan 26, 2015 at 11:53

1 Answer 1

2

ImageMagick ships with config utilities. For Magick++ this utility is Magick++-config. See the Usage sub-section under the API docs.

LDFLAGS=$(Magick++-config --ldflags)
CXXFLAGS=$(Magick++-config --cxxflags)
$(CC) $CXXFLAGS openmpi_project.cc $LDFLAGS -o openmpi_project

Jump over to the MPI compiling/linking docs, and integrate Magick++'s additional flags to mpiCC

LDFLAGS=$(Magick++-config --ldflags)
CXXFLAGS=$(Magick++-config --cxxflags)
mpiCC --with-wrapper-cxxflags=$CXXFLAGS openmpi_project.cc \
      --with-wrapper-ldflags=$LDFLAGS -o openmpi_project
Sign up to request clarification or add additional context in comments.

1 Comment

@emcconville Great answer, had been banging my head over this for a few days now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.