如何使用Visual Studio有条件地与库链接

发布于 01-22 12:49 字数 338 浏览 2 评论 0原文

是否有一个机制(命令行参数,环境变量,配置设置或其他任何)可以在同一Visual Studio项目中允许根据目标Windows版本有条件地链接到库中?

具体来说,如果目标Windows版本比Windows Vista更新,我只想在特定库中链接。

我在Windows 10上进行了编译,我想生成两个构建:

  • 一个用于Windows Vista的构建,该版本 链接中的链接(因为库与Vista不兼容)
  • Windows 7的一个构建和更新确实在库中使用链接,

我正在使用Visual Studio 2015编译。

Is there a mechanism (command line arguments, environment variables, config settings, or anything else) that would allow, within the same Visual Studio project, to conditionally link against a library based on the target Windows version?

Specifically, I want to only link in a particular library if the target Windows version is newer than Windows Vista.

I compile on Windows 10, and I want to produce two builds:

  • One build for Windows Vista that does not link in the library (since the library is not compatible with Vista)
  • One build for Windows 7 and newer that does link in the library

I am compiling using Visual Studio 2015.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆夏时光2025-01-29 12:49:14

简单的方法是创建多个解决方案配置(一种是7和较新的配置,另一个用于Vista),然后将库添加到较新的配置中。这将首先在build ->配置管理器中进行,然后在配置组合中选择“新的”,您将需要为“ debug -vista”,“ warree -vista”创建调试/发行对,然后使用“ edit”来更改现有的“调试”和“发行”到“调试-7”和“发行-7”。

执行此操作后,进入项目设置并更改您的新配置,然后通过将Windows版本指定为预处理器指令并添加库。

这样,您可以执行构建,而无需更改任何实际代码,甚至不得不更改命令行上通过的预处理器指令。

The easy way would be to create multiple solution configurations (one for 7 and newer, the other for vista) then add the library to the newer configuration. This would be done first under Build ->Configuration Manager, and in the Configuration combo select New, You will want to create Debug/Release pair for "Debug - Vista", "Release - Vista" and then use "Edit" to change the existing "Debug" and "Release" to "Debug - 7" and "Release - 7".

After doing this, go into the project settings and change to your new configurations and pass however you specify windows version as preprocessor directives and add the library.

That way you can perform either build without changing any actual code or even having to change the preprocessor directives passed on the command line on an ongoing basis.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文