Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

mingw import library not working with cl

2011-06-01
2013-06-06
  • I am trying to completely transfer the building of import libraries, dlls, static libraries to mingw, and leave only a final linking with cl on windows. I give my libraries to somebody else that uses his cl-built libraries and mine to build a final executable.  I have succeed in all, but the creation of an import library for a dll I build with mingw.

    I have managed to build the .lib on windows with lib /DEF:foo.def (foo.def produced by mingw), and then link and run my program successfully. I am also able to build foo.lib with mingw and link with cl, but the executable throws an error. I tried different ways to build the foo.lib with mingw. In one of those, after a successful linking with cl on windows, during execution it was asking for (null).dll. I had never seen this before.

    SO, is it possible to build import libraries with mingw, and use them to link a dll with cl?  I read this post http://wyw.dcweb.cn/dllfaq.htm from 2004 that says it is not possible. Haven't things changed since?

    Thanks.

     
  • ralph engels
    ralph engels
    2011-08-06

    depends a bit generally C compiled dll's work fine while C++ dll's fail if you try to make an import library.

    its sometime possible but can be a real bitch to get the import names right and requires some hacking around in the def files.

    theres a script for creating import libraries from gnuwin32 site you might try. it can create both mingw and msvc import libraries as well as borland. for a c++ dll it will probably not work though.

     
  • rubenvb
    rubenvb
    2011-08-08

    It's better to use mingw-w64 gendef and MSVC's lib.exe to create import libraries from GCC-built DLL's IMHO.

    info  on gendef, and on lib.exe

    Basically, you'd do this:
    1. build C DLL with MinGW (C++ is not compatible between GCC and MSVC)
    2. execute "gendef dllname.dll"
    3. execute "lib /def:dllname.def /out:dllname.lib"

    Use the .lib file to link. For C this is almost certain to work, for C++ only if you're very lucky, and not recommended.

     
  • ralph engels
    ralph engels
    2011-08-18

    in a few cases you can get away with linking directly to the dll instead of an import library. no guarantees though.