How to import/generate an import library for Embarcadero’s RAD Studio 12.1 64-bit modern (clang 15) C++ compiler?

  Kiến thức lập trình

For the older bcc64 64-bit compiler for C++ Builder, mkexp.exe can be used to import a library. Either I am not using it correctly, or mkexp.exe output files are not compatible with the new Win64x (bcc64x) (modern – clang 15) compiler.

How can a .lib be generated from a .dll for the new compiler?

I tried mkexp.exe (the way that works for the old 64-bit compiler). The Embarcadero wiki does not mention anything about generating .lib files for the new target. Or, if it is documented anywhere, I could not find it.

0

This is addressed in a recent Embarcadero blog post:

How to achieve common tasks with the new Clang toolchain in 12.1

Creating DLL Import Libraries

To import a random DLL, you need an import library. Any existing COFF one should work with our linker (this includes import libraries made by third parties for their DLLs, intended for use with MSVC.)

However, if you need to generate your own, you first need the definition (.def) file for the DLL. To do this, you can use the gendef.exe file from LLVM-MinGW. We aren’t shipping this yet, so you need to download it. Note that the following is third party and not verified or virus-checked by us, but the official llvm-mingw site recommends Martin Storsjö’s github for release. One release is: https://github.com/mstorsjo/llvm-mingw/releases/tag/20220906

Once you’ve found a copy of gendef.exe, run:

gendef file.dll

This will create file.def.

Note: some people have found that the filename in the .def file is incorrect. A .def file is plain text: you can open it and ensure it contains LIBRARY <dllname>.dll where <dllname> might be wrong: we’ve seen just “a” instead of the actual DLL name.

You can then use our new linker to generate the import library (run this at a RAD Studio Command Prompt, or run rsvars.bat in a normal command prompt):

ld.lld.exe -m i386pep --out-implib file.lib file.def

(Or, using the LLVM tools, use llvm-dlltool.exe.)

And you now have an import library for your DLL: for file.dll, you have a file.lib import library.

4

LEAVE A COMMENT