根据VC++条件编译编译器版本

发布于 2024-08-13 21:06:48 字数 455 浏览 3 评论 0原文

我正在将 VC++ 项目从 Visual Studio 2005 (VC8) 迁移到 Visual Studio 2008 (VC9)。解决方案中的某些项目在项目设置的“其他库目录”字段中具有第三方库的路径。路径看起来像这样:
..\SomeLibrary\Lib\vc9\x86

如果我可以使用 Visual Studio 的“属性页宏”之一来替换编译器版本,这将非常有用,就像我可以使用 $(ConfigurationName) 来替换一样用于“调试”或“发布”。像下面这样的东西就完美了:
..\SomeLibrary\Lib\$(CompilerVersion)\x86

不幸的是,我找不到合适的宏。

请注意,当我说“宏”时,我指的是 Visual Studio 的“属性页宏”,而不是 C/C++ 预处理器宏。据我所知,您不能在项目设置中使用预处理器指令。

有谁知道有什么方法可以做到这一点?

I am in the process of migrating our VC++ project from Visual Studio 2005 (VC8) to Visual Studio 2008 (VC9). Some of the projects in the solution have paths to third party libraries in their 'Additional Library Directories' field in the project settings. The paths look something like this:
..\SomeLibrary\Lib\vc9\x86

It would be really useful if I could use one of Visual Studio's "Property Page Macros" to substitute for the compiler version, in much the same way as I can use $(ConfigurationName) to substitue for "Debug" or "Release". Something like the following would be perfect:
..\SomeLibrary\Lib\$(CompilerVersion)\x86

Unfortunately, I can't find an appropriate macro.

Please note that when I say 'macro' I am refering to Visual Studio's "Property Page Macros", not C/C++ preprocessor macros. As far as I am aware you can't use preprocessor directives in the project settings.

Does anyone know of a way to do this?

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

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

发布评论

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

评论(3

桃气十足 2024-08-20 21:06:48

使用 _MSC_VER

#ifndef _MSC_VER
  // not VC++
#elif _MSC_VER < 1400
  // older than VC++ 2005
#elif _MSC_VER < 1500
  // VC++ 2005
#elif _MSC_VER < 1600
  // VC++ 2008
#elif _MSC_VER < 1700
  // VC++ 2010
#else
  // Future versions
#endif

有关更复杂的示例,请参阅 boost 如何处理 VC++ 版本 此处

Use _MSC_VER:

#ifndef _MSC_VER
  // not VC++
#elif _MSC_VER < 1400
  // older than VC++ 2005
#elif _MSC_VER < 1500
  // VC++ 2005
#elif _MSC_VER < 1600
  // VC++ 2008
#elif _MSC_VER < 1700
  // VC++ 2010
#else
  // Future versions
#endif

For a more complicated example, see how boost is dealing with VC++ versions here

我一向站在原地 2024-08-20 21:06:48

您可以使用属性页宏 $(PlatformToolsetVersion) 或 $(PlatformToolset)
例如,对于 vc++ 2012,$(PlatformToolsetVersion) 解析为“110”,$(PlatformToolset) 解析为“v110”。因此,将“vc$(PlatformToolsetVersion)”添加到路径中会在 vc11 下添加“vc110”,或在 vc9 下添加“vc90”。

You could use the property page macros $(PlatformToolsetVersion) or $(PlatformToolset)
For vc++ 2012, for example, $(PlatformToolsetVersion) resolves to "110" and $(PlatformToolset) resolves to "v110". So adding "vc$(PlatformToolsetVersion)" to your path would add "vc110" under vc11 or "vc90" under vc9.

遥远的她 2024-08-20 21:06:48

您是否尝试过_MSC_VER。对于 Microsoft 的 C++ 编译器,这将给出编译器的主要版本号和次要版本号。它可以用作分隔符。

Have you tried _MSC_VER. For Microsoft`s C++ compiler this will give the major and minor version number of the compiler. It could be used as the delimeter.

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