Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get rid of the __imp__ prefix in the linker in VC++?

Tags:

c++

libcurl

I'm using libcurl and am getting the following sort of linker errors in VC++ 10.

1>main.obj : error LNK2019: unresolved external symbol __imp__curl_easy_strerror referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl curl_httpget(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?curl_httpget@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV12@@Z)

How can I get rid of that imp prefix in front of the function name? I am linking to the right lib, right path etc.

like image 705
BeeBand Avatar asked Mar 01 '11 19:03

BeeBand


3 Answers

The __imp__ prefix appears whenever you are linking to a DLL. It does not appear when linking to statically linked libraries. Most likely the code is generated to be linked against a DLL import lib, but you have linked it with a static lib instead.

The prefix is added when you mark the imported function with __declspec(dllimport) - make sure your imports are not using this when not linking against a DLL.

like image 152
Suma Avatar answered Oct 14 '22 17:10

Suma


You have to add CURL_STATICLIB to Preprocessor Definitions at the properties of your projects in MSVC

like image 21
Kostya Trushnikov Avatar answered Oct 14 '22 17:10

Kostya Trushnikov


You are using a header file that defines the function prototype with the specifier evaluating to __declspec(dllimport)

You need to either redefine the statement that is evaluating to this (set it to nothing), or use a different header file altogether.

Typically you'll see code like this:

#ifdef FOO_EXPORTS
#define DLLSPEC __declspec(dllexport)
#else
#define DLLSPEC __declspec(dllimport)
#endif

...

DLLSPEC bool foo(int bar);

Compiling the project with FOO_EXPORTS defined will use one mode and without it will use the other.

like image 11
Mahmoud Al-Qudsi Avatar answered Oct 14 '22 15:10

Mahmoud Al-Qudsi