halivingston
halivingston

Reputation: 3895

Does VC++ add calls to LoadLibrary when using static libraries that don't have code?

Excuse my nomenclature around static libraries, but I mean to talk about the static libraries (.lib) that don't have code, but only references that presumably were generated by taking a dll and making it an import library.

Am I understanding it correctly that the compiler (MSVC++) in this case adds code like LoadLibrary("foo.dll"); GetProcAddress("barMethod"); when referenced in your c++ code?

Is there a way to find out if it truly does that?

Maybe using some sort of static analysis tool that will tell me what code was generated?

Upvotes: 2

Views: 960

Answers (2)

Youw
Youw

Reputation: 879

If you link your program with some library (.lib) that is only an export library for some .dll, the compiler does not call (or add some code of such) any LoadLibrary or smth. And it does not depend on what compiler you are using.

The .dll always loaded (edit: except in case of delay-load linking) by your operating system (in case of using static linking of import library) in the moment when your application starts. The compiler only creating a list of names what must be loaded from .dll. This list is called import table.

Upvotes: 1

MSalters
MSalters

Reputation: 179981

A static library has code. A .lib file without code isn't a static library, but an import library (as you correctly observed).

VC++ can do two things in that case. The default is to compile the import library into the Import Address Table (IAT). At runtime, the OS will then resolve the references. The alternative is called delay-load linking. In that case, VC++ will indeed insert calls to LoadLibrary and GetProcAddress.

Dependency Walker is still the relevant tool to observe how this all works.

Upvotes: 4

Related Questions