使用 ncurses 和 Bazel 构建代码时出错:“unctrl”的类型冲突

问题描述 投票:0回答:1

我有一个用 Bazel 构建的项目,它使用

ncurses
。我正在尝试迁移到 Bazel 8.0.0 LTS 的 bzlmod。以前,我使用的是本地存储库,运行良好。现在,我正在尝试使用 Bazel 中央存储库中的
ncurses
模块。

我在这里有一个最小的重现案例:https://github.com/davidzchen/bazel-ncurses-example

我收到一个关于

conflicting types for 'unctrl'
的奇怪编译错误。这是我收到的错误:

$ bazel build //foo:color --verbose_failures
INFO: Analyzed target //foo:color (0 packages loaded, 0 targets configured).
ERROR: /Users/dzc/Projects/davidzchen/bazel-ncurses-example/foo/BUILD:3:11: Compiling foo/color.cc failed: (Exit 1): cc_wrapper.sh failed: error executing CppCompile command (from target //foo:color)
  (cd /private/var/tmp/_bazel_dzc/87450ce08cbc0c792b19d6253d30d152/sandbox/darwin-sandbox/143/execroot/_main && \
  exec env - \
    PATH='/Users/dzc/Library/Caches/bazelisk/downloads/sha256/ea529c3c03d6981e13e25af126b63b41435c9a42bf28435bbabbe3b11542ddcf/bin:/opt/homebrew/opt/ruby/bin:/opt/homebrew/opt/llvm/bin:/opt/local/bin:/opt/local/sbin:/Users/dzc/.bin:/Users/dzc/.local/bin:/usr/local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Library/TeX/texbin:/Applications/VMware Fusion.app/Contents/Public:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/opt/homebrew/opt/ruby/bin:/opt/homebrew/opt/llvm/bin:/Applications/iTerm.app/Contents/Resources/utilities:/Users/dzc/go/bin:/opt/homebrew/opt/go/libexec/bin:/Library/Frameworks/Mono.framework/Commands:/Users/dzc/.antigen/bundles/robbyrussell/oh-my-zsh/lib:/Users/dzc/.antigen/bundles/robbyrussell/oh-my-zsh/plugins/history-substring-search:/Users/dzc/.antigen/bundles/zsh-users/zsh-syntax-highlighting:/Users/dzc/.antigen/bundles/zsh-users/zsh-completions:/Users/dzc/.antigen/bundles/zsh-users/zsh-autosuggestions' \
    PWD=/proc/self/cwd \
  external/rules_cc++cc_configure_extension+local_config_cc/cc_wrapper.sh -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -Wunused-but-set-parameter -Wno-free-nonheap-object -fcolor-diagnostics -fno-omit-frame-pointer '-std=c++17' '-frandom-seed=bazel-out/darwin_arm64-fastbuild/bin/foo/_objs/color/color.o' -iquote . -iquote bazel-out/darwin_arm64-fastbuild/bin -iquote external/ncurses+ -iquote bazel-out/darwin_arm64-fastbuild/bin/external/ncurses+ -isystem external/ncurses+/include -isystem bazel-out/darwin_arm64-fastbuild/bin/external/ncurses+/include -isystem external/ncurses+/ncurses -isystem bazel-out/darwin_arm64-fastbuild/bin/external/ncurses+/ncurses '-mmacosx-version-min=15.2' -MD -MF bazel-out/darwin_arm64-fastbuild/bin/foo/_objs/color/color.d '-std=c++20' -c foo/color.cc -o bazel-out/darwin_arm64-fastbuild/bin/foo/_objs/color/color.o -no-canonical-prefixes -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -Xclang '-fmodule-name=//foo:color' -Xclang '-fmodule-map-file=bazel-out/darwin_arm64-fastbuild/bin/foo/color.cppmap' -Xclang -fno-cxx-modules -fmodules-strict-decluse -Wprivate-header -Xclang '-fmodule-map-file=external/rules_cc++cc_configure_extension+local_config_cc/module.modulemap' -Xclang '-fmodule-map-file=bazel-out/darwin_arm64-fastbuild/bin/external/ncurses+/ncurses.cppmap')
# Configuration: 9b382b18c38178c86436d40b630070f6a7b54b2d54b8541e3a8dda9e825538d4
# Execution platform: @@platforms//host:host

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
In file included from foo/color.cc:3:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/ncurses.h:2918:
bazel-out/darwin_arm64-fastbuild/bin/external/ncurses+/include/unctrl.h:61:54: error: conflicting types for 'unctrl'
   61 | NCURSES_EXPORT(NCURSES_CONST char *) NCURSES_SP_NAME(unctrl) (SCREEN*, chtype);
      |                                                      ^
bazel-out/darwin_arm64-fastbuild/bin/external/ncurses+/include/unctrl.h:58:38: note: previous declaration is here
   58 | NCURSES_EXPORT(NCURSES_CONST char *) unctrl (chtype);
      |                                      ^
1 error generated.
Target //foo:color failed to build
INFO: Elapsed time: 2.201s, Critical Path: 0.91s
INFO: 97 processes: 11 internal, 86 darwin-sandbox.
ERROR: Build did NOT complete successfully

有趣的是,

bazel build @ncurses
成功了。

令我感到奇怪的是,Bazel 是从系统而不是从远程存档中找到

ncurses.h

我也尝试将

common --incompatible_strict_action_env
添加到我的
.bazelrc
,但我仍然遇到相同的错误。

有谁知道导致此问题的原因以及如何解决它?

我正在使用 Bazel 8.0.0,并且使用的是 macOS Sequoia 15.2

bazel ncurses bazel-rules bazel-cpp
1个回答
0
投票

感谢 GitHub 上的 @wep21,我解决了这个问题:

deps
cc_library
目标的
cc_binary
中,我们需要同时包含
"@ncurses//:ncurses_headers",
@ncurses
。此外,文件需要
#include <curses.h>
而不是
#include <ncurses.h>
。请参阅此提交了解更多详细信息。

此外,函数

refresh
box
不可用(尽管我不确定为什么),并且这些函数需要替换为对
wrefresh
wborder
的调用。请参阅此提交了解更多详细信息。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.