我正在尝试将程序集(使用 yasm
编译)与 msvc
/cl.exe
编译的对象结合起来,我正在尝试链接(使用 link.exe
)到 .dll
,然后链接到最终的可执行文件。
从源代码创建对象文件以及从这些对象创建 dll 都可以正常工作。
在最后一步中,将 .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
内导出。
有什么想法如何满足链接器并告诉他符号确实存在吗?
最佳答案
如您所见,问题是 DLL 没有公开所需的符号。 __declspec(dllexport)
并不是导出符号的唯一方法。如果您有一些导出的名称,您可以使用 /EXPORT
链接器开关。另一种选择是使用 Module-Definition文件。
关于c - 将编译代码与 NASM 和 MSVC 链接时 Unresolved reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38729747/