views:

123

answers:

2

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?

+3  A: 

It's not possible in general - static libraries and executables are completely different kinds of animal. The way to handle this situation is to create two projects - one for the library, which contains all the functionality. and one for the executable, which is a thin wrapper that simply calls functions in the library.

anon
But right here I have a vcproj file that DOES end up with both an exe and a lib... Yet for the life of me I couldn't find what made it do that.http://svn.corecraft.org/aspire_mirror/trunk/win/VC90/hearthstone-world.vcproj
Spidey
@Spidey Presumably the project contains two sub-projects.
anon
agreed. Make the exe project depend on the lib project and it'll get automatically recompiled when needed.
f4
I see, one of the projects in the solution was actually a static library which the other used, just like you've suggested. Thanks! :)
Spidey
A: 

You don't "also link a lib", you create a static library project. The latter doesn't call the linker at all -- instead it compiles all your files with cl /c and combines the resulting .objs into a lib using lib.exe.

Alex