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

标签 c visual-c++ dll libcurl unresolved-external

我一直坚持使用 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" 

所以...我真的很困惑为什么这三个函数无法解析。有什么想法要检查什么或如何进一步调查吗?

最佳答案

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

关于c - MSVC 2015/libcurl/未解析的外部 _curl_easy_init@0 等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44724570/

相关文章:

c++ - 链接器错误构建 GDAL

c++ - 不同编译器中的 std::filesystem 和 std::experimental::filesystem 问题

c# - 如何将 C++ 结构从 dll 传输到 C# 程序?

c - mifare desfire 中的 ISO14443-4(RATS)

c - 在 OSX 10.10 上安装 GCC 4.4.7

c++ - 使用 Win32 API 在 C++ 中使用多线程创建多个文件

dll - WinXP下如何修复DWMAPI.DLL延迟加载依赖?

c - 为当前运行的线程重用 pthread_t 变量

c - 使用gets读取二维字符串

c - 对库包含的函数的 undefined reference