Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magick++ in VS2010 - unresolved external symbol

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!

like image 520
Van Coding Avatar asked Dec 21 '10 12:12

Van Coding


People also ask

How do I fix unresolved external symbol?

So when we try to assign it a value in the main function, the linker doesn't find the symbol and may result in an “unresolved external symbol” or “undefined reference”. The way to fix this error is to explicitly scope the variable using '::' outside the main before using it.

How do I fix lnk2001?

To fix this issue, add the /NOENTRY option to the link command. This error can occur if you use incorrect /SUBSYSTEM or /ENTRY settings in your project. For example, if you write a console application and specify /SUBSYSTEM:WINDOWS, an unresolved external error is generated for WinMain .


2 Answers

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.

like image 71
Hans Passant Avatar answered Oct 23 '22 04:10

Hans Passant


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)

like image 34
Stephane Rolland Avatar answered Oct 23 '22 02:10

Stephane Rolland