Reputation: 1691
My present goal is compiling, say, the SQLite library (C-language), statically linked with dependencies on Windows with MSVC Build Tools. I want to get a single DLL file, which may only depend on the core Windows/VC components, such as kernel32 or VC runtime. SQLite library has several extensions with external dependencies, for example, Zipfile/zlib or ICU/ICU. I want to enable these extensions with all necessary code statically linked in the sqlite3.dll file. I can compile it with dynamic linking just fine, but it requires separate dll dependency files, which is what I want to avoid.
Micorosoft has a basic tutorial Walkthrough: Create and use a static library, but I do not see clear instructions on how to do it from the MSVC Build Tools command line. My understanding is that to link a dependency statically, a static library file .lib is required. At the same time, import libraries also have the .lib extension.
I have several questions:
Upvotes: 1
Views: 2731
Reputation: 1691
Ok, after further exploration, it seems I have the answers.
The first question was asked here before here, and there is an interesting comment related to libraries created with MinGW (one more relevant MinGW-related question). There are several options, and the simplest appears to be lib /list sqlite3.lib
, which should list objects for a static library and produce no output for the import library.
The answer to the second question is given by Misrosoft, stating that
The default mode for LIB is to build or modify a library of COFF objects. LIB runs in this mode when you do not specify /EXTRACT (to copy an object to a file) or /DEF (to build an import library).
The third question was discussed before here, and it appears that the answer is "yes". Come to think of it, a static library should contain the actual objects and no information about a DLL (which could have been created independently). The lib file is not good for use at run-time either way, so the only possibility for successful linking against static libraries should be the static mode.
Upvotes: 1