ncurses.h

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

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

ncurses
,我正在尝试将其迁移到 Bazel 8.0.0 LTS 的 bzlmod。我正在尝试使用 Bazel 中央存储库中的
ncurses
模块。

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

当我尝试在 Ubuntu 24.04.1 LTS(通过 WSL)上构建存储库时,我收到一条错误,指出未找到

ncurses.h

$ bazel build //foo:color --verbose_failures
INFO: Analyzed target //foo:color (0 packages loaded, 0 targets configured).
ERROR: /home/dzc/Projects/davidzchen/bazel-ncurses-example/foo/BUILD:3:11: Compiling foo/color.cc failed: (Exit 1): gcc failed: error executing CppCompile command (from target //foo:color)
  (cd /home/dzc/.cache/bazel/_bazel_dzc/0eea61d75b5304f994b8af9040b68be8/sandbox/linux-sandbox/162/execroot/_main && \
  exec env - \
    PATH='/home/dzc/.bin:/home/dzc/.local/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Program Files/Microsoft SQL Server/150/Tools/Binn/:/mnt/c/Program Files/Microsoft SQL Server/Client SDK/ODBC/170/Tools/Binn/:/mnt/c/Program Files/dotnet/:/mnt/c/Program Files (x86)/Windows Kits/10/Windows Performance Toolkit/:/mnt/c/ProgramData/chocolatey/bin:/mnt/c/Program Files/Git/cmd:/mnt/c/Users/david/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/david/AppData/Local/Programs/Microsoft VS Code/bin:/mnt/c/Users/david/.dotnet/tools:/home/dzc/go/bin:/usr/lib/go/bin:/home/dzc/.antigen/bundles/robbyrussell/oh-my-zsh/lib:/home/dzc/.antigen/bundles/robbyrussell/oh-my-zsh/plugins/history-substring-search:/home/dzc/.antigen/bundles/zsh-users/zsh-syntax-highlighting:/home/dzc/.antigen/bundles/zsh-users/zsh-completions:/home/dzc/.antigen/bundles/zsh-users/zsh-autosuggestions' \
    PWD=/proc/self/cwd \
  /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++17' -MD -MF bazel-out/k8-fastbuild/bin/foo/_objs/color/color.pic.d '-frandom-seed=bazel-out/k8-fastbuild/bin/foo/_objs/color/color.pic.o' -fPIC -iquote . -iquote bazel-out/k8-fastbuild/bin -iquote external/ncurses+ -iquote bazel-out/k8-fastbuild/bin/external/ncurses+ -isystem external/ncurses+/include -isystem bazel-out/k8-fastbuild/bin/external/ncurses+/include -isystem external/ncurses+/ncurses -isystem bazel-out/k8-fastbuild/bin/external/ncurses+/ncurses '-std=c++20' -c foo/color.cc -o bazel-out/k8-fastbuild/bin/foo/_objs/color/color.pic.o -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"')
# Configuration: 333f6f4c7cf3276607d148778aaf5f43ecbd710ad44e62c36ff54f462d3b62af
# Execution platform: @@platforms//host:host

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
foo/color.cc:3:10: fatal error: ncurses.h: No such file or directory
    3 | #include "ncurses.h"
      |          ^~~~~~~~~~~
compilation terminated.
Target //foo:color failed to build
INFO: Elapsed time: 0.525s, Critical Path: 0.12s
INFO: 10 processes: 9 internal, 1 linux-sandbox.
ERROR: Build did NOT complete successfully

如果将

#include "ncurses.h"
更改为
#include <ncurses.h>
,我会得到同样的错误。奇怪的是,存储库根目录中的
find -L . -name "ncurses.h"
不返回任何结果,而在 ncurses 源树中搜索不同的文件(例如
codes.c
)确实返回结果:

$ find -L . -name "ncurses.h"
$ find -L . -name "codes.c"
./bazel-bin/external/ncurses+/ncurses/codes.c
./bazel-out/k8-fastbuild/bin/external/ncurses+/ncurses/codes.c
./bazel-bazel-ncurses-example/bazel-out/k8-fastbuild/bin/external/ncurses+/ncurses/codes.c

Ubuntu版本信息:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 24.04.1 LTS
Release:        24.04
Codename:       noble

有谁知道为什么会发生这种情况以及我该如何解决这个问题?预先感谢您。

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.