如何使Bazel荣誉Windows上的CC环境变量?

发布于 2025-02-04 06:51:28 字数 396 浏览 4 评论 0原文

我正在尝试使用Bazel在Windows上构建针对MingW32的程序。没有内置的编译器,因此我必须尝试以某种方式伪造它。

在Linux上,我可以对任何类似于GCC的编译器进行编译:

CC=path-to-some-compiler-gcc bazel build ...

这显然在Windows上不起作用,因为Bazel默认使用MSVC,我没有。但这也不起作用 - cc变量被忽略:

CC=path-to-some-compiler-gcc bazel build --compiler=mingw_windows

有没有办法获得我在Linux上看到的相同行为,但是在Windows上看到了相同的行为?

I'm trying to use bazel to build a program against mingw32 on Windows. There isn't a built-in compiler for this, so I have to try and fake it somehow.

On Linux, I can compile against any gcc-like compiler with this:

CC=path-to-some-compiler-gcc bazel build ...

This doesn't work on Windows, obviously, since bazel defaults to using MSVC, which I don't have. But this also doesn't work --- the CC variable is ignored:

CC=path-to-some-compiler-gcc bazel build --compiler=mingw_windows

Is there a way to get the same behaviour I'm seeing on Linux, but on Windows?

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

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

发布评论

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

评论(1

月棠 2025-02-11 06:51:28

var = value命令是一种类似bash的语法,所以显然cc = to to Path to to path to path to some-compiler-gcc bazel build ...如果您不don' t使用这样的任何外壳。为了使用它,您必须在Windows上安装bash或类似的外壳。在本机Windows Shell(CMD和PowerShell)中,该变量是单独设置的。您需要在CMD中喜欢这样做:

set "CC=path-to-some-compiler-gcc"
bazel build --compiler=mingw_windows

并且

$env:CC = "path-to-some-compiler-gcc"
bazel build --compiler=mingw_windows

在MSYS2中的PowerShell中,您需要导出cc = to Path to path to path to some-compiler-gcc使环境变量可用于Win32应用程序,否则该变量仅在当前的bash会话中包含

VAR=value command is a bash-like syntax so obviously CC=path-to-some-compiler-gcc bazel build ... won't work if you don't use any shells like that. To use that you must install bash or similar shells on Windows. In native Windows shells (cmd and PowerShell) the variable is set separately. You need to do like this in cmd:

set "CC=path-to-some-compiler-gcc"
bazel build --compiler=mingw_windows

and like this in PowerShell

$env:CC = "path-to-some-compiler-gcc"
bazel build --compiler=mingw_windows

In MSYS2 you'll need export CC=path-to-some-compiler-gcc to make the environment variable available to Win32 apps, otherwise the variable will be contained in the current bash session only

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