say I built an application called App1 with a lot of开发者_高级运维 classes in a single project. And I decide that I want to build another project called App2 and I want to use those same classes so I decide to turn App1 into a lib file. Must I remove the WinMain function to do so or can I leave it and the compiler will ignore the winMain in the lib file. ??
Particularly in Visual Studio your static library won't cause troubles in any case. Even though you can add your WinMain
(or console main
) to a static library, your only chance to use it in your second project is by explicitly seeting Linker-System-Subsystem
to appropriate type.
In this case if you match the routine (WinMain
for windows subsystem and main
for console), then you can actually compile your second project without defining the main
routine in it and main
would be linked from your library.
Still, in this situation, if you declare that main
and ALSO link your library, your local main
will have priority and will be called, so that main
in library will be ignored.
So, there is actually no difference for you if you export you function to the library or not, you can leave it and it won't be used unless you make what I've pointed to earlier.
It just doesn't make any sense to do this. Spin the classes off in their own library project that builds a .lib, have both apps use the library.
精彩评论