On Wed, 29 Dec 2021, Gisle Vanem wrote:

Martin Storsjö wrote:

In the meantime, when you create your regular import library with an
option like -Wl,--out-implib,libfoo.dll.a, add the
option -Wl,--output-def,foo.def. After that, run "dlltool -d foo.def -l
libfoo.dll.a". This recreates the import library
in a form that works better with MS link.exe.

Thanks a lot.

Maybe I have to add '--kill-at' too?

Yes, possibly - if you're exporting stdcall/fastcall functions.

These are my steps:
  gcc -o ../bin/liquid32.dll -shared -m32 \
      -static-libgcc \
      -Wl,--out-implib,../liquid32.dll.a \
      -Wl,--output-def,MinGW_obj32/liquid32.def \
      MinGW_obj32/libliquid.o
      ...

And:
  dlltool --input-def MinGW_obj32/liquid32.def --dllname liquid32.dll \
       --output-lib ../liquid32_imp.lib --kill-at --machine i386

But now I get tons of warnings from 'link.exe'.
Like:
  Loaded liquid32_imp.lib(dolms02750.o)
  module 'liquid32_imp.lib(dolms02750.o)' unsafe for SAFESEH image.

and lots of these:
  liquid32_imp.lib(dolms00002.o) :
  error LNK2001: unresolved external symbol __head____liquid32_imp_lib

What's these '__head____*' symbols?

For reference my dlltool has version
  (GNU Binutils) 2.36.1

Hmm, that's quite strange - is there any difference if you'd name the file liquid32.dll.a instead of liquid32_imp.lib? Because technically, the new file you generated and the one from --out-implib from ld should be virtually identical, except for the minor detail that makes it break when linking two of them with MS link.exe.

The __head__* symbols are internal details in the import libs. The import libs consist of a bunch of object files. When you have a reference against e.g. myLibFunc, there's one object in the import lib that provides it. That object file then has a reference to symbols defined in a separate header object file in the import library.

Make sure you only specify this new import library to link.exe, not the old version of it.

If you inspect the new import lib with nm, I would expect it to have one object file providing the symbol that you mentioned to be missing.

(When inspecting import libs with nm, you'll notice that the ld produced import libs all have the same filename stem for the object files inside the archive, while the ones from dlltool have unique stems. This is what mixes them up when linking two of them with MS link.exe)

// Martin

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to