Page 1 of 1

Can't use Magick++ under Windows with Code::Blocks

Posted: 2017-05-08T06:39:48-07:00
by kikill
Good morning everyone,

I'm new on c++ and I would like to use magick++ to make some tricks with images.
I read a lot of thing on internet but I can't figure out how to use magick++.

I saw a lot of thing about the folder Magick++_demo and the button.cpp file. So that's what I did :

I open Code::Blocks and I import a visual workspace and I select Magick++_Demo.dsw, I select the Gnu gcc compiler and here after importing all the files, I get a first error : "Fail to import *any* projects from workspace file. Well, why not ? Maybe there is no project file, only a workspace, all the files are imported.

I try to compile the button.cpp and I get an error about Magick++.h : No such file or directory.
After reading a lot of thing, I figured out that I needed to link the library. So that's what I did :
Project > Build options > Select Button > Search Directories > Compiler > C:\Program Files\ImageMagick-7.0.5-Q16\include
So, all the input file are linked
Project > Build options > Select Button > Search Directories > Link > C:\Program Files\ImageMagick-7.0.5-Q16\lib
So, all the lib are linked
Project > Build options > Select Button > Linker Settings :
I add the three libraries : CORE_RL_Magick++_.lib CORE_RL_MagickCore_.lib CORE_RL_MagickWand_.lib

So now, he found Magick++.h ! That's good right ? :) But nop, it still not working and that's why I'm there. I search like all the day why this shitty thing happen and I saw that I'm not the only one who faces this problem. But I never saw a solution for this problem. I get errors about undefined reference !

Code: Select all

||=== Build: default in button (compiler: GNU GCC Compiler) ===|
.objs\button.o:button.cpp|| undefined reference to `Magick::InitializeMagick(char const*)'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Color::Color(char const*)'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Image::Image()'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Geometry::Geometry(std::string const&)'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Image::size(Magick::Geometry const&)'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Geometry::~Geometry()'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Image::read(std::string const&)'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Image::Image(std::string const&)'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Image::texture(Magick::Image const&)'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Color::Color(std::string const&)'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Image::fillColor(Magick::Color const&)'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Color::~Color()'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Image::fontPointsize(double)'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Image::annotate(std::string const&, MagickCore::GravityType)'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Image::borderColor(Magick::Color const&)'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Geometry::Geometry(char const*)'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Image::frame(Magick::Geometry const&)'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Geometry::~Geometry()'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Image::depth(unsigned int)'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Image::quantizeDither(bool)'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Image::quantizeColors(unsigned int)'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Image::quantize(bool)'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Image::compressType(MagickCore::CompressionType)'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Image::write(std::string const&)'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Image::~Image()'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Image::~Image()'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Color::~Color()'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Geometry::~Geometry()'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Color::~Color()'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Geometry::~Geometry()'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Image::~Image()'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Image::~Image()'|
.objs\button.o:button.cpp|| undefined reference to `Magick::Color::~Color()'|
||error: ld returned 1 exit status|
||=== Build failed: 34 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|
If someone know how to fix these undefined reference.
I saw that solution on the net but I don't know how to use it :
g++ `Magick++-config --cxxflags --cppflags` -o CmdLineClient CmdLineClient.cpp `Magick++-config --ldflags --libs`

where can I write this command compiler (I think it's a command to build the project) on Code::Blocks ?

Thank's in advance guys !

Re: Can't use Magick++ under Windows with Code::Blocks

Posted: 2017-05-08T07:18:25-07:00
by snibgo
I don't use Code::Blocks and don't know the answer.

"undefined reference" means the program compiled but couldn't link. So you are not linking against the correct libraries.

You can see that the suggested compilation command includes...

Code: Select all

Magick++-config --ldflags --libs
... as a back-ticked subcommand. I don't know how you would tell Code::Blocks to include that. The Code::Blocks documentation may tell you.

You can run that command and see what libraries are needed, and then include those in your project.

Re: Can't use Magick++ under Windows with Code::Blocks

Posted: 2017-05-12T04:42:35-07:00
by kikill
As I said I link the library. I search where to put that command but I didn't find any way to use it on Code::Blocks so, I try to put it on different places but nothing happened.

Did someone use code::blocks here ?

Re: Can't use Magick++ under Windows with Code::Blocks

Posted: 2019-03-21T17:42:44-07:00
by Asimov
I have no problem compiling in visual studio but would prefer to use codeblocks. Did you ever get it working?

Re: Can't use Magick++ under Windows with Code::Blocks

Posted: 2019-04-03T03:42:02-07:00
by imPhil
I don't know Code::Blocks, so I'm guessing a bit.... This sounds like a "name mangling" problem. In C++ function names are mangled to include things like parameter types. This mangling is compiler specific (even sometimes changing from one version of the same compiler to another). Linking C++ DLLs built with one compiler is never going to work on another compiler, unless they are specifically designed to be "compatible". MSVC is the defacto standard for Windows development, so I would not be surprised if Code::Blocks has a switch to make it do MSVC compatible name mangling.