Last night I spend multiple hours trying to get a non-broken CSFML build ready, which requires to have import libraries for MSVC and GCC that both depend on the same DLL. This works because the import library only points to the symbols that are in the DLL, thus acts as sort of instruction how to use the DLL.
Now in the past, I’ve been using an ancient tool called LIB2A which was written in Visual Basic and you can find it on some archived Google Code site. The tool still works, but as was pointed out quite a while ago on the SFML forum, the generated DEF files do not contain “typedef-ed” types, such as specific blend modes or specific colors. For CSFML this would mean that if you used the GCC import library, you would be able to use sfBlue or sfBlendNone despite the DLL having these symbols.
So the broken step was generating a DEF file from a LIB or DLL file. Unfortunately the internet wasn’t very helpful for once and I kept running into weird solutions that didn’t work or tools (e.g. EXPDEF) that were only supporting x86 architecture, I even tried some commercial tool from RAD Studio (MKEXP), but that didn’t work either. I tried different versions of the reimp.exe which is part of MinGW-Utils, but it turns out that was last updated in 2009 (!) and the latest version doesn’t even work.
Only after multiple hours of searching I finally stumbled up on the mentioning of gendef.exe which is shipped with MinGW-w64 distributions and oh look, it’s sole purpose is to generate DEF files from DLLs. With gendef and dlltool, both part of any MinGW-w64 distribution, you can now quite easily generate GCC import libraries from any DLL.
gendef.exe csfml-graphics-2.dll dlltool.exe -d csfml-graphics-2.def -D csfml-graphics-2.dll -l libcsfml-graphics.a
gendef generates a DEF file in the working directory and dlltool generates a GCC A import library.
I’m mainly putting this information out here, in hopes Google will pick it up and people looking for similar solutions won’t have to spend the same amount of time finding gendef.