2

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?

Leandros
  • 16,805
  • 9
  • 69
  • 108

1 Answers1

2

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.

Sergio
  • 8,099
  • 2
  • 26
  • 52
  • Unfortunately more than just a few functions, making `/EXPORT` unfeasible. Can I combine an already created .lib to link the dll with another create via the def file? – Leandros Aug 02 '16 at 20:45
  • Yes, DEF file is just a list of functions that you wish to export (plus some extra info). It doesn't affect functionality of resulting binaries. And of course you should check that functions appear at export table with `dumpbin`. – Sergio Aug 02 '16 at 21:03
  • While this works, it's unfortunately only half a solution. I can't add every symbol by hand to my build flags or the def file. – Leandros Aug 03 '16 at 03:24
  • Why so? It shouldn't be more difficult than adding dllexport specifier to each functions in source code. – Sergio Aug 03 '16 at 05:12
  • It is more difficult. Requires special treatment in my makefiles, which is a pain to maintain since I have hundreds of functions I have to export. – Leandros Aug 03 '16 at 05:50