Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create both a .lib file and an .exe file in Visual C++?

I currently have a console project which creates an .exe file; I want it to also create a .lib file so other projects, compiled as DLLs, would be able to call functions from the original project.

I know it is possible, but I couldn't find how to do that. How do I tell the linker to also link a .lib?

like image 822
MoshiBin Avatar asked Apr 17 '10 11:04

MoshiBin


People also ask

How do I run a .LIB EXE file?

The easiest way is to use the "Visual Studio Command Prompt", you'll find it in the Start menu, Microsoft Visual Studio 2010, Visual Studio Tools. Next, run lib.exe with the /def:foo.

Can a exe link to DLL and static library at the same time?

Yes, the Core and Utils code will be duplicated. Instead of building them as static libs you can build them as dlls and use anywhere.

What is Lib EXE?

The Microsoft Library Manager (LIB.exe) creates and manages a library of Common Object File Format (COFF) object files. LIB can also be used to create export files and import libraries to reference exported definitions.


1 Answers

Posting this just as a reference I know the original post was posted long time ago but this still applies to anyone who needs a solution to this problem.

Go to the project you want to make a .lib file for and follow these steps:

  1. Right click on the project.
  2. Select Properties.
  3. Select Build Events.
  4. Select Pre-Link Event .
  5. Finally in the Command Line paste this:

    @ECHO ON @ECHO "$(VC_ExecutablePath_x86)\lib.exe" /out:"$(OutDir)$(ProjectName).lib" "$(IntermediateOutputPath)*.obj" "$(VC_ExecutablePath_x86)\lib.exe" /out:"$(OutDir)$(ProjectName).lib" "$(IntermediateOutputPath)*.obj"

This will call the lib tool to generate the lib file out of the generated object files.

like image 127
Eyal Alon Avatar answered Oct 19 '22 03:10

Eyal Alon