'How to convert a dynamic dll to static lib?
I write a program helloworld.exe; it depends on a.dll. I don't have the source code of the a.dll, which is a dynamic dll. How can i change it to static library, so I can link it into helloworld.exe?
Solution 1:[1]
Sorry, but there's no direct way to do so. A DLL is a fully linked executable format file, where a static library is a collection of separate object files collected together. With a little bit of work, you can convert a static library to a DLL, but doing the reverse is non-trivial (to put it mildly).
Solution 2:[2]
As Jerry said, you cannot do it directly. You can, however, package your program into something like a self extracting RAR file which includes the DLL as part of the single EXE, which automatically extracts the EXE and associated DLLs to a temp folder and starts the main program.
Solution 3:[3]
False, it is possible to do this. For example there is a tool called dlltolib which can do it.
Solution 4:[4]
I agree with Jerry, and if it is a deployment problem, you may use Nullsoft Scriptable Install System.
Solution 5:[5]
On windows, you can get the lib file to run your program if you have the corresponding def file. You can use the command prompt window of visual studio to get the lib file. The command line is as follows: lib /def:XXX.def /machine:x64 (or x86 to get 32bit lib)/out:XXX.lib. You need to make sure the def file and dll file are in the same folder and you have changed the directory to the folder.
Solution 6:[6]
Perhaps what is being asked is how to create a .LIB file that will permit statically linking to the .DLL. Here are sample commands to achieve this:
set DUMPBIN="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx86\x86\dumpbin.exe"
set LIBX="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx86\x86\lib.exe"
set IN="\MyFolder\MyDll.dll"
set DEF="\MyFolder\MyDll.def"
set LIB="\MyFolder\MyDll.lib"
:: [1] run dumpbin
%DUMPBIN% /EXPORTS /NOLOGO /OUT:%DEF% %IN%
:: [2] edit .DEF file to look proper
:: [3] run LIB
%LIBX% /DEF:%DEF% /OUT:%LIB%
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jerry Coffin |
| Solution 2 | Billy ONeal |
| Solution 3 | |
| Solution 4 | baris.aydinoz |
| Solution 5 | |
| Solution 6 | Pierre |
