如何管理生成静态库和 dll 的构建库项目?
我有一个包含约 50 个项目的大型视觉工作室解决方案。有 StaticDebug、StaticRelease、Debug 和 Release 的配置。有些库需要 dll 和静态库两种形式。为了获得它们,我们使用不同的配置重建解决方案。配置管理器窗口用于设置哪些项目需要在哪些风格、静态库、动态 dll 或两者中构建。
这管理起来相当棘手,而且必须多次构建解决方案并按正确的顺序选择配置,这有点烦人。静态版本需要在非静态版本之前构建。
我想知道,对于我需要生成静态库和动态 dll 的项目,我创建了两个项目,而不是当前的方案,管理起来是否会更简单。例如:
- CoreLib
- CoreDll
我可以让这两个项目引用所有相同的文件并构建它们两次,或者我想知道是否可以构建 CoreLib 然后让 CoreDll 链接它以生成 dll?
我想我的问题是,您对如何在这种情况下构建项目有什么建议吗?
谢谢。
I've got a large visual studio solution with ~50 projects. There are configurations for StaticDebug, StaticRelease, Debug and Release. Some libraries are needed in both dll and static lib form. To get them, we rebuild the solution with a different configuration. The Configuration Manager window is used to setup which projects need to build in which flavours, static lib, dynamic dll or both.
This can by quite tricky to manage and it's a bit annoying to have to build the solution multiple times and select the configurations in the right order. Static versions need building before non-static versions.
I'm wondering, instead of this current scheme, might it be simpler to manage if, for the projects I needed to produce both a static lib and dynamc dll, I created two projects. Eg:
- CoreLib
- CoreDll
I could either make both of these projects reference all the same files and build them twice, or I'm wondering, would it be possible to build CoreLib and then get CoreDll to link it to generate the dll?
I guess my question is, do you have any advice on how to structure your projects in this kind of situation?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在资源管理器中将原始项目文件复制为 CoreLib.vcxproj (如果是其他 VS,请检查适当的扩展名)
将 CoreLib.vcxproj 作为现有项目添加到您的解决方案中并保存您的解决方案。
转到CoreLib的属性->配置属性->常规。
选择所有配置(左上角)。
将属性配置类型更改为静态库。
将属性 目标扩展 更改为 .lib 。
附加到属性中间目录,例如 \Lib\ 。
转到属性->配置属性->C/C++->预处理器
选择调试配置(左上角)。
现在编辑属性预处理器定义并将行_USRDLL更改为_USRLIB
选择发布配置(左上角)。
现在编辑属性 Preprocessor Definitions 并将行 _USRDLL 更改为 _USRLIB
在您的头文件中,您应该有类似以下内容:
将其更改为类似于以下内容:
现在您的构建生成原始 dll 和导入库以及新的静态库!
Make a copy your original project file in explorer as CoreLib.vcxproj (in case of other VS check the appropiate extension)
Add CoreLib.vcxproj as an existing project to your solution and save your solution.
Go to the properties->Configuration Properties->General of CoreLib.
Select all Configurations (left upper corner).
Change property Configuration type to static library.
Change property Target Extension to .lib .
Append to property Intermediate directory for example \Lib\ .
Go to the properties->Configuration Properties->C/C++->Preporcessor
Select Debug Configuration (left upper corner).
Now edit the property Preprocessor Definitions and change the line _USRDLL into _USRLIB
Select Release Configuration (left upper corner).
Now edit the property Preprocessor Definitions and change the line _USRDLL into _USRLIB
In your header-file you should have something like the following:
change it into something like the following :
Now your Build generates your original dll and import lib as well as a new static lib !
也许您可以检查像 CMake 这样的构建系统会为这种情况生成什么。我猜它会为每个案例生成两个项目。但通过这种方式创建解决方案可能会为您节省大量工作。
Maybe you could check what a build system like CMake produces for this case. I'm guessing it will generate two projects for each case. But by creating the solution this way it could possibly save you a lot of work.