Search code examples
c++visual-studiodllimport

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


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?


Solution

  • By selecting 'Class Library' you were accidentally telling it to make a .Net Library using the CLI (managed) extenstion of C++.

    Instead, create a Win32 project, and in the Application Settings on the next page, choose 'DLL'.

    You can also make an MFC DLL or ATL DLL from those library choices if you want to go that route, but it sounds like you don't.