MSVC 2015 / libcurl / 未解析的外部_curl_easy_init@0等

MSVC 2015 / libcurl / unresolved externals _curl_easy_init@0 etc

提问人:Robert M. Münch 提问时间:6/23/2017 最后编辑:Robert M. Münch 更新时间:6/25/2017 访问量:236

问:

我被困在编译使用 libcurl 静态版本的 DLL 上。我得到以下三个函数作为未解析的外部函数:

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

下面是链接器操作的截图:

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)

所以我的代码使用 curl_easy_setopt(...),它不会产生任何问题,并且只是在我使用 curl_easy_init(...) 的同一区域

使用 dumpbin.exe 查看 libcurl.lib 中的符号,我看到:

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

哪个 IMO 显示符号 os 包含。至少它看起来与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

这是我使用 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" 

所以。。。我真的很困惑为什么这三个功能无法解决。任何要检查什么或如何进一步调查的想法?

C visual-c++ DLL libcurl 未解析的外部

评论

0赞 nos 6/23/2017
如果您静态链接到 curl,我认为您还必须为所有使用 curl 的代码定义 CURL_STATICLIB 宏 - 参见 curl.haxx.se/docs/faq.html#Link_errors_when_building_libcur
0赞 Robert M. Münch 6/24/2017
我这样做,对不起,发布了错误的命令行。固定。
0赞 Robert M. Münch 6/25/2017
好吧,我走得更远一点。问题在于调用约定不同。我的DLL使用__stdcall,libcurl使用__cdecl。当我尝试使用 __stdcall 编译 libcurl 时,我不得不更改一些函数签名以保持__cdecl。但后来我的测试程序崩溃了......知道为什么 libcurl 不在 Windows 上使用 __stdcall 吗?如何让它__stdcall使用?

答:

0赞 Robert M. Münch 6/25/2017 #1

原来是调用约定。因此,请确保所有使用 libcurl 的部分都使用调用约定__cdecl。