Multiple project output types: compiling as an EXE and a LIB

廉价感情. 提交于 2019-12-24 14:04:07

问题


I have a C++ project that builds as an EXE. However I also need to build the project as a static library (.LIB file). Right now in order to get a complete build, I need to build it in one format, then open the project properties and under General > Project Defaults > Configuration Type select the other format, accept, and recompile. It's a real hassle. Is there some way of specifying both types? I haven't seen anything on MSDN on this.

I'm using Visual Studio 2012.


回答1:


A common (and particularly sane) way to solve your problem is to have a solution containing two projects. The first project should be a library (statically or dynamically linked, it doesn't matter) that contains most of your code. The second project should be an executable that references the library you've created in your first project.

Do it this way and a single build of your solution will produce both the executable and the library.




回答2:


Create two projects, add the same set of source files to both.



来源:https://stackoverflow.com/questions/17758022/multiple-project-output-types-compiling-as-an-exe-and-a-lib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!