I'm trying to combine assembly (compiled with yasm
) with objects compiled by msvc
/cl.exe
, which I'm trying to link (with link.exe
) into a .dll
, which is then linked to the final executable.
Both creating the object files from source, and creating the dll from these objects works absolutely fine.
In the last step, linking the .dll
with the executable spits out following errors:
error LNK2019: unresolved external symbol xxx_xxxx
I'm using C. Despite Win64 having no name mangling, I tried multiple schemes (like _xxx_xxxx
or __imp_xxx_xxxx
).
Examining the object file with dumpbin.exe
reveals all symbols:
$ 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
But not in the exported symbols from the .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
[...]
Even though I have marked the declarations as exported inside the .dll
by using __declspec(dllexport)
.
Any ideas how to satisfy the linker and tell him the symbols are indeed there?
As you see the problem is that DLL doesn't expose required symbol. __declspec(dllexport)
is not the only way to export your symbols. If you have a few exported names you can use /EXPORT
linker switch. Another alternative is to use Module-Definition file.