且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用SCons TryCompile检查Windows上的编译器标志支持

更新时间:2023-11-10 17:48:52

让它再次出现在游行队伍中:)显然,Windows编译器不管发生什么,总是返回成功。

Leave it to Windows to rain on the parade once again :) Obviously the Windows compiler always returns success, irregardless of what happens.

我可以想到几种可以尝试的选择。

I can think of several options that you could try.

首先,SCons提供了多平台配置(Autoconf功能),可以帮助您达到相同的结果。它不包含任何用于编译器选项的内容,但至少包含以下内容:

First of all, SCons provides a Multi-Platform Configuration (Autoconf Functionality) which may help you achieve the same result. It doesnt include anything for compiler options, but does at least includes the following:


  • 检查头文件的存在

  • 检查功能的可用性

  • 检查库的可用性

  • 检查typedef的可用性

  • 添加您自己的自定义支票

  • Checking for the Existence of Header Files
  • Checking for the Availability of a Function
  • Checking for the Availability of a Library
  • Checking for the Availability of a typedef
  • Adding Your Own Custom Checks

另一种选择是使用以下方法构建某种词典: Microsoft编译选项。每个编译器版本可能需要一个字典。此特定选项可能需要花费很长时间来准备,并且可能不值得。

Another option would be to build some sort of a dictionary with the Microsoft compilation options. You would probably need one dictionary per compiler version. This particular option would probably take a long time to prepare, and probably wouldnt be worth it.

另一种选择是改用Object()或Program()生成器TryCompile()构建器,然后尝试 catch 失败并做出相应反应。我不确定SCons是否允许您将编译失败作为异常捕获并在失败时继续执行,但是值得检查。

Another option would be to use the Object() or Program() builder instead of the TryCompile() builder, and try to catch the failure and react accordingly. Im not sure if SCons allows you to catch compilation failures as an exception and carry on if it fails, but its worth checking into.