0

I'm stucked at getting a DLL compiled that uses libcurl static version. I get the following three functions as unresolved external:

1>curl.obj : error LNK2001: unresolved external symbol _curl_easy_init@0
1>curl.obj : error LNK2001: unresolved external symbol _curl_easy_perform@4
1>curl.obj : error LNK2001: unresolved external symbol _curl_easy_cleanup@4

Here is a snip from the linker action:

1>Searching libraries
1>      Searching D:\develop\rm-asset\c-code\libs\libcurl.lib:
1>        Found _curl_easy_setopt
1>          Referenced in curl.obj
1>          Loaded libcurl.lib(easy.obj)
1>        Found _curl_slist_free_all
1>          Referenced in libcurl.lib(easy.obj)
1>          Loaded libcurl.lib(slist.obj)

So my code uses curl_easy_setopt(...) which doesn't make any problems and is just in the same area where I use curl_easy_init(...)

Taking a look at the symbols in libcurl.lib with dumpbin.exe I see:

SECTION HEADER #B
.text$mn name
       0 physical address
       0 virtual address
      3D size of raw data
    5D25 file pointer to raw data (00005D25 to 00005D61)
    5D62 file pointer to relocation table
       0 file pointer to line numbers
       3 number of relocations
       0 number of line numbers
60501020 flags
         Code
         COMDAT; sym= _curl_easy_init
         16 byte align
         Execute Read

Which IMO shows that the symbol os contained. At least it looks very similar as for curl_easy_setopt:

SECTION HEADER #17
.text$mn name
       0 physical address
       0 virtual address
      23 size of raw data
    7245 file pointer to raw data (00007245 to 00007267)
    7268 file pointer to relocation table
       0 file pointer to line numbers
       1 number of relocations
       0 number of line numbers
60501020 flags
         Code
         COMDAT; sym= _curl_easy_setopt
         16 byte align
         Execute Read

This is the compiler command line for my application using libcurl:

    /GS /debug:expr-source-pos /analyze /W3 /Zc:wchar_t /I"d:\develop\rm-
asset\c-code\include" /I"D:\develop\rm-asset\c-code\extensions\qq-pun-mel-l\src"
 /O3 /Fd"R_Extended_Aliased\vc140.pdb" /fp:precise /fp:extended /D 
"REAL_T_EXTENDED" /D "_HAVE_SQLITE_CONFIG_H" /D "SQLITE_ENABLE_REDEF_IO=1" /D 
"SQLITE_ENABLE_CEROD=1" /D "SQLITE_DLL=1" /D "SQLITE_HAS_CODEC=1" /D 
"BUILDING_DLL" /D "R2" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_USRDLL" /D 
"SAPHIRIONDLL_EXPORTS" /D "ZLIB_WINAPI" /D "NDEBUG" /D "CURL_STATICLIB" /D"USE_WINDOWS_SSPI" /D "USE_SCHANNEL" /D "USE_WIN32_IDN" /D "WANT_IDN_PROTOTYPES" 
/D "_WINDLL" /D "_UNICODE" /D "UNICODE" /D "SQLITE_ENABLE_SESSION" /D 
"SQLITE_ENABLE_PREUPDATE_HOOK" /Zc:forScope /Gz /MT /Fa"R_Extended_Aliased\" 
/EHsc /nologo /Fo"R_Extended_Aliased\" /Qprof-dir "R_Extended_Aliased\" /Ot 
/Fp"R_Extended_Aliased\saphirion.pch" 

So... I'm really puzzled why those three functions can't be resolved. Any ideas what to check or how to further investigate?

  • If you link to curl statically, I think you have to also define the CURL_STATICLIB macro for all your code that uses curl - see https://curl.haxx.se/docs/faq.html#Link_errors_when_building_libcur – nos Jun 23 '17 at 15:13
  • I do this, sorry posted wrong command line. Fixed. – Robert M. Münch Jun 23 '17 at 16:00
  • Ok, I'm a bit further. The problem are different calling conventions. My DLL uses __stdcall, libcurl uses __cdecl. When I try to compile libcurl with __stdcall, I had to change some function signatures to stay __cdecl. But then my test program crashes... Any idea why libcurl isn't using __stdcall on Windows? How to make it use __stdcall? – Robert M. Münch Jun 24 '17 at 18:34

1 Answers1

0

It turned out to be the calling convention. So, ensure all parts using libcurl use __cdecl calling convention.