e.exe
is linked against my custom static library, c.lib
, which uses Win32 API defined in w.dll
. w.dll
is located in C:\Windows\System32 and its import library is w.lib
, located in Windows SDK directory. Shell w.lib
be listed as Additional Dependency in c.lib
or e.exe
project? (e.exe
builds successfully in both cases.) What is the best practice and why? I guess e.exe
should not know about w.lib
.
c.lib
is intended to be shared among a group of developers only (not to be shipped to customers).
TEST: I used VS2008 and dumpbin utility to test both cases and here are results:
- Case 1:
w.lib
added as Additional Dependency inc.lib
project.
dumpbin /archivemembers c.lib
output lists both offsets in w.dll
and .obj files from c.lib
project as Archive members.
- Case 2:
w.lib
not added as Additional Dependency inc.lib
but ine.exe
project:
This time, dumpbin output contains only .obj files of c.lib
and the size of c.lib
is smaller than in Case 1
(c.lib
was added as Additional Dependency in w.exe
project in both cases.)
NOTE: I used w.lib
and w.dll
here as fictional, generic names for Windows libraries but they could be e.g. Userenv.lib and Userenv.dll or Version.lib and Version.dll...
I think you're misunderstanding what creating an archive and an import archive does.
Creating an archive, as you've rightly surmised in comments, creates a unified file containing compiled .objs. Now, this can contain any code you like, including but not limited to dynamic calls to libraries. An import library is a library that contains an obj that exclusively makes such calls, the idea being that by importing it, your exe can find the appropriate symbols (they must be in the executable you create).
The process of creating
c.lib
fromw.lib
simply extractsw.lib
's objects and appends them to the collection of objects inc.lib
. In effect,c.lib
becomes an import library + code.Do I think you should do this? Not really - it might lead to confusion as to what
e.exe
depends on; I think you should explicitly make this visible rather than trying to hide it. That said, that's a recommendation only, not a rule.Libraries are not linked, so any project that uses a .lib also needs its dependencies.
Basically the .lib are "copied" to your exe during linking.
If you want to avoid your users to explicity link againts w.lib, transforms c.lib in a dll, dlls are linked and you do not need their dependencies during build.