How do I build an import library (.lib) AND a DLL in Visual C++?

David Grayson picture David Grayson · Feb 25, 2009 · Viewed 136.5k times · Source

I want to have a single Visual Studio project that builds a DLL file and an import library (.lib) file. (An import library is a statically-linked library that takes care of loading that DLL file in other projects that use it).

So I went to Visual Studio C++ 2008 Express Edition, created a New Project of type Class Library, and set the "Configuration Type" to be "Dyanamic Library (.dll)".

But when I build the solution, the only relevant output file I see is a DLL file; I don't see any LIB file getting generated. I looked in the project directory and all subdirectories (Release and Debug).

I believe that it is possible to build a LIB and a DLL file at the same time because on the MSDN it says "The linker creates the import library when the DLL is built." Also, another user of this website is creating LIB and DLL files at the same time using Visual C++.

So how can I do it?

Answer

Michael Burr picture Michael Burr · Feb 25, 2009

Does your DLL project have any actual exports? If there are no exports, the linker will not generate an import library .lib file.

In the non-Express version of VS, the import libray name is specfied in the project settings here:

Configuration Properties/Linker/Advanced/Import Library

I assume it's the same in Express (if it even provides the ability to configure the name).