将已编译代码与 NASM 和 MSVC 链接时未解析的引用
Unresolved Reference when linking compiled code with NASM and MSVC
我试图将程序集(用 yasm
编译)与 msvc
/cl.exe
编译的对象结合起来,我试图 link(用link.exe
) 到 .dll
,然后 linked 到最终的可执行文件。
从源代码创建对象文件和从这些对象创建 dll 都工作得很好。
在最后一步中,link使用可执行文件 .dll
发出以下错误:
error LNK2019: unresolved external symbol xxx_xxxx
我正在使用 C。尽管 Win64 没有名称修改,但我尝试了多种方案(例如 _xxx_xxxx
或 __imp_xxx_xxxx
)。
检查带有 dumpbin.exe
的目标文件会显示所有符号:
$ dumpbin /symbols myobj.o
File Type: COFF OBJECT
COFF SYMBOL TABLE
000 00000000 DEBUG notype Filename | .file
002 00000000 SECT1 notype Static | .text
Section length 215, #relocs 0, #linenums 0, checksum 0
004 00000057 SECT1 notype External | xxx_xxxx
005 0000013E SECT1 notype External | xxx_xxxx
006 00000000 SECT1 notype External | xxx_xxxx
但不在 .dll
:
的导出符号中
$ dumpbin /exported mylib.dll
File Type: DLL
Section contains the following exports for mylib.dll
00000000 characteristics
57A0FE02 time date stamp Tue Aug 02 22:09:38 2016
0.00 version
1 ordinal base
132 number of functions
132 number of names
[...]
即使我已使用 __declspec(dllexport)
.
将声明标记为在 .dll
中导出
有什么想法可以让 linker 满意并告诉他这些符号确实存在吗?
如您所见,问题是 DLL 没有公开所需的符号。 __declspec(dllexport)
不是导出符号的唯一方法。如果您有一些导出的名称,您可以使用 /EXPORT
linker switch. Another alternative is to use Module-Definition 文件。
我试图将程序集(用 yasm
编译)与 msvc
/cl.exe
编译的对象结合起来,我试图 link(用link.exe
) 到 .dll
,然后 linked 到最终的可执行文件。
从源代码创建对象文件和从这些对象创建 dll 都工作得很好。
在最后一步中,link使用可执行文件 .dll
发出以下错误:
error LNK2019: unresolved external symbol xxx_xxxx
我正在使用 C。尽管 Win64 没有名称修改,但我尝试了多种方案(例如 _xxx_xxxx
或 __imp_xxx_xxxx
)。
检查带有 dumpbin.exe
的目标文件会显示所有符号:
$ dumpbin /symbols myobj.o
File Type: COFF OBJECT
COFF SYMBOL TABLE
000 00000000 DEBUG notype Filename | .file
002 00000000 SECT1 notype Static | .text
Section length 215, #relocs 0, #linenums 0, checksum 0
004 00000057 SECT1 notype External | xxx_xxxx
005 0000013E SECT1 notype External | xxx_xxxx
006 00000000 SECT1 notype External | xxx_xxxx
但不在 .dll
:
$ dumpbin /exported mylib.dll
File Type: DLL
Section contains the following exports for mylib.dll
00000000 characteristics
57A0FE02 time date stamp Tue Aug 02 22:09:38 2016
0.00 version
1 ordinal base
132 number of functions
132 number of names
[...]
即使我已使用 __declspec(dllexport)
.
.dll
中导出
有什么想法可以让 linker 满意并告诉他这些符号确实存在吗?
如您所见,问题是 DLL 没有公开所需的符号。 __declspec(dllexport)
不是导出符号的唯一方法。如果您有一些导出的名称,您可以使用 /EXPORT
linker switch. Another alternative is to use Module-Definition 文件。