简体   繁体   English

QBS构建系统,无法使用vcvars64.bat初始化环境

[英]QBS build system, can't initialize environment with vcvars64.bat

I'm trying to implement my own module to build C++ on Windows with clang-cl toolchain as there's no built-in support in QBS right now. 我正在尝试实现自己的模块,以便使用clang-cl工具链在Windows上构建C ++,因为QBS目前没有内置支持。

I chose to use lld-link instead of microsoft linker, so I have to supply it with all the MS library include paths manually. 我选择使用lld-link而不是Microsoft链接程序,因此我必须手动为其提供所有MS库包含路径。 With these paths hardcoded, I manage to build my apps fine. 通过这些路径的硬编码,我可以很好地构建我的应用程序。 But I'd like to make my module more flexible and use %LIB% environment variable set by vcvars32.bat | 但是,我想使我的模块更加灵活,并使用vcvars32.bat设置的%LIB%环境变量。 vcvars64.bat

As far as I understand, this could (should?) be done inside module's setupBuildEnvironment script. 据我了解,这可以(应该?)在模块的setupBuildEnvironment脚本中完成。 Here's what I try to read the %LIB% and fail: 这是我尝试读取%LIB%并失败的内容:

import qbs.Environment
import qbs.Process

Module
{
    setupBuildEnvironment:
    {
        var p = new Process();
        p.exec("vcvars64.bat", [], true);
        // makes no difference
        // p.exec("cmd", ["/c", "vcvars64.bat"], true);
        var lib = p.getEnv("LIB");
        // this fails too
        // var lib = Environment.getEnv("LIB");
        console.info("LIB = " + lib);
        p.close();
    }
    ...
}

This gives me LIB = so I'm getting nowhere. 这给了我LIB =所以我无处可去。 My guess is that the process is already terminated at the moment of querying the variable ( p.getEnv("LIB") ), hence the empty result. 我的猜测是,在查询变量( p.getEnv("LIB") )时,该过程已经终止,因此结果为空。 The QBS docs for Process.getEnv() state nothing in this regard. 在这方面,针对Process.getEnv()的QBS文档没有任何规定。

What is the correct QBS way to initialize environment with vcvars64.bat , and more broadly, what is the correct way to get environment of a process inside setupBuildEnvironment ? vcvars64.bat初始化环境的正确QBS方法是什么,更广泛地讲,在setupBuildEnvironment获取进程环境的正确方法是什么?


[update] Well, embarassingly, this was easy to work around by creating a simple batch and getting rid of setupBuildEnvironment script altogether: [更新]令人尴尬的是,通过创建一个简单的批处理并完全摆脱setupBuildEnvironment脚本,可以轻松解决此问题:

 @echo off
 call vcvars64 && qbs

But I'd like to avoid batch scripting as much as possible, so the question still stands. 但是我想尽可能避免批处理脚本,因此问题仍然存在。

The vars batch files just dump some information onto the console. vars批处理文件只是将一些信息转储到控制台上。 That does not set an environment on the calling process in any way. 这不会以任何方式在调用进程上设置环境。 You would need to parse the process output. 您将需要解析流程输出。 I suggest you take a look at the MsvcProbe item in the qbs sources to see how that is implemented for MSVC. 我建议您看一看qbs源中的MsvcProbe项,以了解如何为MSVC实施。 You might be able to adapt the code for clang-cl. 您可能可以将代码改编为clang-cl。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Visual Studio 2019:使用 vcvars64.bat 从命令行构建 C++ 不再有效 - Visual Studio 2019: build C++ from command line with vcvars64.bat doesn't work anymore 如何在eclipse中构建代码之前运行vcvars32.bat? - How can I run vcvars32.bat before code build in eclipse? 尝试在 c++ 程序中通过 system() function 使用 cl Visual Studio 命令进行命令行构建时出现 vcvars32.bat 问题 - Issue with vcvars32.bat when trying to use cl Visual Studio command for command line build via the system() function in a c++ program 是否有人在 Visual Studio 中成功修改了 vcvars*.bat 以指向共享构建工具位置并能够使用 MSBuild? - Has anyone successfully modified vcvars*.bat in Visual Studio to point to a shared build tools location and been able to use MSBuild? 为什么我不能在QBS项目中使用控制台输出? - Why i can't use console output in QBS project? 静态构建Qt + Qbs - Static build Qt+Qbs 无法在x64中构建gdal - Can't build gdal in x64 如何使用 QBS 在构建阶段安装柯南 package - How to install conan package on build stage with QBS 无法构建Boost 64位动态库,只能构建静态 - Can't build Boost 64 bit dynamic libraries, only static 我无法建立需要WOW64 Api的库 - I can't build a library that needs WOW64 Api
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM