1
#include <iostream>
#include <Magick++.h>

int main()
{
    Magick::InitializeMagick(NULL);
    Magick::Image im;
    im.read("/home/chase/Desktop/m42.jpg");
    im.display();
    return 0;
}

I get the following error when I try to compile in eclipse...

Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -std=c++0x -I/usr/include/x86_64-linux-gnu/ImageMagick-6 -I/usr/include/ImageMagick-6 -O0 -g3 -Wall -c -fmessage-length=0 -fopenmp -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
Finished building: ../main.cpp

Building target: Stacking
Invoking: GCC C++ Linker
g++ -L../ -o "Stacking"  ./main.o   -lMagick++-6.Q16 -lMagickWand-6.Q16 -lMagickCore-6.Q16 -lMagick++-6.Q16 -lMagickWand-6.Q16 -lMagickCore-6.Q16
./main.o: In function `main':
/home/chase/workspace/Stacking/Debug/../main.cpp:8: undefined reference to `Magick::Image::read(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status
makefile:44: recipe for target 'Stacking' failed
make: *** [Stacking] Error 1

Why does the read function not compile. I used the package config tool in eclipse to set up Magick++. Also as far as I can tell all the other functions work fine. I am using Ubuntu. I installed Magic++ using sudo apt-get install libmagick++-dev.

Update: I got it to work. I had upgraded to g++-5. When I compiled with g++-4.9 it worked. Wonder why it does not work with g++-5?

chasep255
  • 11,745
  • 8
  • 58
  • 115

1 Answers1

3

Why does the read function not compile

Your read function does compile. What you have is a link problem.

why it does not work with g++-5

Because g++-4.x and g++-5.x use different ABI, and are not link-compatible (and your libMagick* libraries were built with g++-4.x).

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • Is there a way to recompile Magick++ for g++-5. Or get a version which works with it? – chasep255 Aug 28 '15 at 12:36
  • @chasep255 Certainly: `Magic++` is open-source, so you *can* download and compile it with `g++-5.x`. See "building from source" here: http://www.imagemagick.org/Magick++/Install.html – Employed Russian Aug 28 '15 at 14:18