使用 Visual Studio 2022 编译,Windows。
代码如下:
#include "curl/curl.h"
#include <cstdio>
#include <cstdlib>
using namespace std;
#ifdef _DEBUG
#pragma comment(lib, R"(【Debug,屏蔽】)")
#else
#pragma comment(lib, R"(【Release,屏蔽】)")
#endif
int main()
{
curl_global_init(CURL_GLOBAL_ALL);
return 0;
}
(我确定【屏蔽】是正确的 lib。)
不管是 Debug 还是 Release 都有这个错误。
Release 版,运行 dumpbin 有:
dumpbin /SYMBOLS ./【Release,屏蔽】 | findstr curl_global_init
072 00000000 SECT1E notype () External | curl_global_init
073 00000000 SECT20 notype () External | curl_global_init_mem
0DD 00000000 SECT30 notype Static | $unwind$curl_global_init
0E0 00000000 SECT31 notype Static | $pdata$curl_global_init
0E3 00000000 SECT32 notype Static | $unwind$curl_global_init_mem
0E6 00000000 SECT33 notype Static | $pdata$curl_global_init_mem
libcurl 的编译过程是:在官网下载 curl-8.11.1.zip,直接解压。然后运行 winbuild/makedebug.bat,就得到了 Debug 版。
makedebug.bat 只有一行真正有用:
nmake.exe /f Makefile.vc mode=static DEBUG=yes GEN_PDB=yes
于是我们把 DEBUG=yes 改成 DEBUG=no,就得到了 Release 版。
错误信息:
1>------ 已启动全部重新生成: 项目: 【屏蔽】, 配置: Release 【连 x86 还是 x64 都要屏蔽】 ------
1>【屏蔽】.cpp
1>【屏蔽】.obj : error LNK2001: 无法解析的外部符号 __imp_curl_global_init
1>【屏蔽】.exe : fatal error LNK1120: 1 个无法解析的外部命令
1>已完成生成项目“【屏蔽】.vcxproj”的操作 - 失败。
又发现信息:是静态链接的。但是像改 DEBUG=yes 一样把 mode=static 改为 mode=dynamic 直接出现:
Microsoft (R) 程序维护实用工具 14.【版本号也要屏蔽】 版
版权所有 (C) Microsoft Corporation。 保留所有权利。
Invalid mode: dynamic
See winbuild/README.md for usage
Makefile.vc(41) : fatal error U1050: please choose a valid mode
Stop.
所以怎么办啊,bdfs 无果。