【问题标题】:Is there a way to detect the version of Windows in a build.rs?有没有办法在 build.rs 中检测 Windows 的版本?
【发布时间】:2020-03-12 00:31:49
【问题描述】:

正如标题所说。我正在 build.rs 中构建一些 C 文件,我需要根据 Windows 的版本有条件地设置一些定义/有条件地链接库。有没有办法检测到?

【问题讨论】:

    标签: rust conditional-compilation


    【解决方案1】:

    当然。 例如nt_version crate,您可以使用它在编译时检测Windows 版本。请注意,您可能会针对不同的 Windows 版本“交叉编译”(例如,在 Windows 7 上开发 Windows 10 或类似版本)。

    这是一个关于如何使用它的小 sn-p:

    use nt_version;
    
    fn main() {
        let version: &str;
        match nt_version::get() {
            (6, 0, _) => version = "Windows Vista",
            (6, 1, _) => version = "Windows 7",
            (10, _, _) => version = "Windows 10",
            _ => version = "Unsupported!",
        }
    
        println!("cargo:warning={}", version);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-24
      • 1970-01-01
      • 1970-01-01
      • 2021-12-07
      • 1970-01-01
      • 2020-11-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多