7

I'm trying to use ImageMagick Magick++ for a C++ Project in VS2010. I installed the Library from here: klick

Then in my Project, I added c:/program files/ImageMagick-6.6.6-Q16/include to the include folders. Then I tried to use Magick++ with this code:

#include <Magick++.h>
void main(int argc, char ** argv){
    InitializeMagick(*argv);
}

But this does not work! VS2010 returns the following errors:

error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl    Magick::InitializeMagick(char const *)" (__imp_?InitializeMagick@Magick@@YAXPBD@Z)
error LNK1120: 1 unresolved externals

What am I doing wrong?

Thanks very much for your help!

UPDATE:

Set Linker -> Input -> Additionnal Dependencies to:

kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;CORE_RL_Magick++_.lib

And Linker -> General -> Additionnal Library Directories to:

C:\Program Files\ImageMagick-6.6.6-Q16\lib

It still results in the same error...

UPDATE 2

Opening the .lib files in C:\Program Files\ImageMagick-6.6.6-Q16\lib results in this error: alt text

UPDATE 3

CORE_RL_Magick++_.lib does contain ?InitializeMagick@Magick@@YAXPEBD@Z, but not ?InitializeMagick@Magick@@YAXPBD@Z. Does this mean the .lib file is corrupted?

UPDATE 4

I solved my problem by manually compliling the .lib files. Thanks to all!

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Van Coding
  • 24,244
  • 24
  • 88
  • 132

4 Answers4

3

CORE_RL_Magick++_.lib does contain ?InitializeMagick@Magick@@YAXPEBD@Z, but not ?InitializeMagick@Magick@@YAXPBD@Z

Using the undname.exe utility, these names undecorate to:

void __cdecl Magick::InitializeMagick(char const *)
void __cdecl Magick::InitializeMagick(char const * __ptr64)

Note the __ptr64 declarator you got on the argument. You've got some kind of compile setting that turns that char* into a 64-bit pointer. Like compiling this code targeting a 64-bit operating system. But linking the 32-bit .lib. This normally generates a linker error about the bit-ness of the .lib being wrong, not so sure why you don't see this. Maybe a mingw artifact, not sure how it works.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Have you any idea you should I turn targeting to 32 bit on 64 bit machine? My problem is totally the same - I just want to use the `YAXPEBD` function instead of the `YAXPBD` that cannot be found... – Tomáš Zato Nov 22 '14 at 03:47
  • Just wanted to mention this was the key to my problem. Was using x64 libraries and trying to compile to x86. Downloading the x86 ImageMagick and using those for x86 worked for me. – ug_ Aug 07 '17 at 09:55
2

You should also indicate to Visual Studio the .lib to be used for linking

in Linker -> Input -> Additionnal Dependencies

EDIT: and put the path of the magick library

in Linker -> General -> Additionnal Library Directories

EDIT2: if it still doesnt work, then you are calling a fonction with a wrong exported signature. Launch the msdev tool Dependency Walker. And check if the magick.lib really exports the function whose name is ?InitializeMagick@Magick@@YAXPBD@Z

I am wrong it's not a microsoft tool: Dependency Walker

I was wrong Dependency Walker doesnt open .lib, only Dlls and Exes. However since you have found ?InitializeMagick@Magick@@YAXPBD@Z in the content of the .lib file, it means that it is reaaly exported this way.

EDIT3: Are you SURE the name and the folder of the additionnal library is correct. I really cannot think of another reason for Visual C++ being unable to link with your library. If your .lib DO contains the string ?InitializeMagick@Magick@@YAXPBD@Z I really think it should link.

EDIT4: could you paste from the file <Magick++.h> the prototype definition of InitializeMagick ? there is something that makes it be compiled differently between visual c++ and your library supplier. ?InitializeMagick@Magick@@YAXPEBD@Z and ?InitializeMagick@Magick@@YAXPEBD@Z are two DIFFERENT signatures. When including <Magick++.h> Visual C++ understands its differently. (that's why I need to see the prototype of the function)

Stephane Rolland
  • 38,876
  • 35
  • 121
  • 169
  • Ok. I tried it with dependency walker. Opening CORE_RL_Magick++_.lib fails. "At least one file was not a 32-bit or 64-bit Windows module." – Van Coding Dec 21 '10 at 13:17
  • one of your file may be corupted maybe... but could you tell us precisely which libraries are failing ? does Depedency Walkers show them, - highlighted in red I think - ? Or doesnt it completely fail ? – Stephane Rolland Dec 21 '10 at 13:22
  • In the lib folder, there are 4 .lib files, I get the same error on all files, when I try to open them with dependency walker. When I manually search in the file for InitializeMagick@Magick@@YAXPBD@Z, I can find it. So its there. Are all files corrupted? – Van Coding Dec 21 '10 at 13:30
  • the dependency walker tool is only designed for *.dll and *.exe files, not for *.lib files, so its not surprising that i cannot open that file... – smerlin Dec 21 '10 at 13:35
  • ^^ alright! In addition: could it be, that my x64 system is the problem? – Van Coding Dec 21 '10 at 13:47
  • STRANGE: It does contain ?InitializeMagick@Magick@@YAXPEBD@Z, but not ?InitializeMagick@Magick@@YAXPBD@Z. Does this mean the .lib file is corrupted? – Van Coding Dec 21 '10 at 14:17
  • I think you got what the linker doesnt like... let me check the mangling definition. I don't speak mangling names fluently ;-) but it does mean that you try to link with a different version of the function that is exported. That's the problem. – Stephane Rolland Dec 21 '10 at 15:28
  • According to an old documentation I am reading PEBD is the correct mangling name for when exporting const char *. But I cannot find what PBD matches to. – Stephane Rolland Dec 21 '10 at 15:46
  • void MagickDLLDecl InitializeMagick(const char * path_); – Van Coding Dec 21 '10 at 16:48
  • look at Hans Passant's answer, he has undecorated the names. hans says is about some 64bits features turned on. I can help you no longer with 64bit, not my field ;-) – Stephane Rolland Dec 21 '10 at 17:07
  • `1>LINK : fatal error LNK1104: cannot open file 'C:\Program Files\ImageMagick\lib.obj'` what the hell? – Tomáš Zato Nov 22 '14 at 02:32
0

You should also indicate to Visual Studio the .lib to be used for linking in Linker -> Input -> Additionnal Dependencies

Thank you! The additional dependecies line contains now the following text (look at the end): kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;C:\Program Files\ImageMagick-6.6.6-Q16\lib\CORE_RL_Magick++_.lib

It still does not work. Is it the wrong .lib file?

what is this .lib file for? Shouldn't source code just work? There isn't any DLL...

Van Coding
  • 24,244
  • 24
  • 88
  • 132
  • 1
    You shouldnt put the path in the name of the lib – Stephane Rolland Dec 21 '10 at 12:52
  • In linker -> General -> Additionnal Library Directories – Stephane Rolland Dec 21 '10 at 12:54
  • Ok, added path (C:\Program Files\ImageMagick-6.6.6-Q16\lib\) to linker -> General -> Additionnal Library Directories and libname (CORE_RL_Magick++_.lib) to Linker -> Input -> Additionnal Dependencies. It still does not work... :S – Van Coding Dec 21 '10 at 13:00
  • It **should** work now ;-). Check the path, if the .lib is really here. Do a clean/rebuild if ever there is mess in temporary compilation files. If there is still a trouble, then you may call a function with the wrong signature. I m gonna edit my post if it is ever the case – Stephane Rolland Dec 21 '10 at 13:08
  • Cleaning & Rebuild does not seem to work. Paths are (unfortunately) correct. – Van Coding Dec 21 '10 at 13:38
  • For me, there were three LIB files (not only one like your case). It could be my version 7.1.0. In general, the LIB file is the executable related function without recompiling. Also (as Stephane Rolland mentioned) please check if you put the same directory (not file) in Linker -> General -> Additional Library Directories. – Cloud Cho Mar 03 '22 at 23:40
0

The documentation says: "Windows users may get started by manually editing a project file for one of the Magick++ demo programs." Did you try that?

hmuelner
  • 8,093
  • 1
  • 28
  • 39