无法找到本机库“(null)”:错误 0xc1
错误代码0xc1
is a Windows系统错误代码 https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499- :
ERROR_BAD_EXE_FORMAT
193 (0xC1)
%1 is not a valid Win32 application.
通过使用检查 DLL 的标头dumpbin https://learn.microsoft.com/en-us/cpp/build/reference/dumpbin-reference?view=msvc-160
> dumpbin /headers my_c_dll.dll
Microsoft (R) COFF/PE Dumper Version 14.26.28806.0
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file my_c_dll.dll
PE signature found
File Type: DLL
FILE HEADER VALUES
14C machine (x86)
4 number of sections
6043A8CB time date stamp Sat Mar 6 17:07:39 2021
0 file pointer to symbol table
0 number of symbols
E0 size of optional header
2102 characteristics
Executable
32 bit word machine
DLL
我观察到它说machine (x86)
and 32 bit word machine
,所以我怀疑该DLL是32位DLL。但是,我在 64 位机器上:
> PowerShell -Command "systeminfo | perl -nE 'say if /System Type/'"
System Type: x64-based PC
事实证明,Build Tools for Visual Studio 2019
除了“VS 2019 的开发者命令提示符”之外,还安装了一些更多的开发者提示符,即:
- VS 2019 的 x64 本机工具命令提示符
- VS 2019 的 x64_x86 交叉工具命令提示符
- VS 2019 的 x86 本机工具命令提示符
- VS 2019 的 x86_x64 交叉工具命令提示符
通过打开“VS 2019 的 x64 Native Tools 命令提示符”并在此处重新编译 DLL,我现在得到:
> dumpbin /headers my_c_dll.dll
Microsoft (R) COFF/PE Dumper Version 14.26.28806.0
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file my_c_dll.dll
PE signature found
File Type: DLL
FILE HEADER VALUES
8664 machine (x64)
6 number of sections
6043AAA2 time date stamp Sat Mar 6 17:15:30 2021
0 file pointer to symbol table
0 number of symbols
F0 size of optional header
2022 characteristics
Executable
Application can handle large (>2GB) addresses
DLL
请注意,输出现在显示machine (x64)
and Application can handle large (>2GB) addresses
,这似乎也解决了这个问题:
> raku test-dll.raku
Hello from C