Linux
如何抑制所有被視為格式截斷錯誤的警告
我正在嘗試使用 gcc 8.3.0 建構我的原始碼
root@eqx-sjc-engine2-staging:/usr/local/src# gcc --version gcc (Debian 8.3.0-2) 8.3.0 Copyright (C) 2018 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. root@eqx-sjc-engine2-staging:/usr/local/src#
我收到以下錯誤
libs/esl/fs_cli.c:1679:43: error: '%s' directive output may be truncated writing up to 1023 bytes into a region of size 1020 [-Werror=format-truncation=] snprintf(cmd_str, sizeof(cmd_str), "api %s\nconsole_execute: true\n\n", argv_command); libs/esl/fs_cli.c:1679:3: note: 'snprintf' output between 29 and 1052 bytes into a destination of size 1024 snprintf(cmd_str, sizeof(cmd_str), "api %s\nconsole_execute: true\n\n", argv_command); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors make[2]: *** [Makefile:2693: fs_cli-fs_cli.o] Error 1 make[2]: Leaving directory '/usr/local/src' make[1]: *** [Makefile:3395: all-recursive] Error 1 make[1]: Leaving directory '/usr/local/src' make: *** [Makefile:1576: all] Error 2
我嘗試像下面那樣執行make
make -Wno-error=format-truncation
我仍然看到同樣的問題。
我的linux版本是
root@eqx-sjc-engine2-staging:~# cat /etc/os-release PRETTY_NAME="Debian GNU/Linux buster/sid" NAME="Debian GNU/Linux" ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/"
如何解決?
根據 makefile,您可能需要以下內容:
make CFLAGS="-Wno-error=format-truncation"
預設的 Makefile 規則和大多數編寫良好的 Makefile 應該看到
CFLAGS
正在使用的 C 編譯器的選項參數。同樣,您可以CXXFLAGS
用於為 C++ 編譯器和LDFLAGS
連結器提供選項。
./configure --enable-fatal-warnings=no