我正在尝试使用 GCC 版本 >= 12 编译 gcc 编译器,当我运行时
make
我收到以下错误
tti -I../../../../gittea/gcc/libcpp -I.
-I../../../../gittea/gcc/libcpp/../include
-I../../../../gittea/gcc/libcpp/include -c -o expr.o -MT expr.o
-MMD -MP -MF .deps/expr.Tpo ../../../../gittea/gcc/libcpp/expr.cc
../../../../gittea/gcc/libcpp/expr.cc: In function ‘unsigned int
cpp_classify_number(cpp_reader*, const cpp_token*, const char**,
location_t)’:
../../../../gittea/gcc/libcpp/expr.cc:842:35: error: format not a
string literal and no format arguments [-Werror=format-security]
842 | cpp_warning_with_line (pfile, CPP_W_LONG_LONG,
virtual_location,
|
~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
843 | 0, message);
| ~~~~~~~~~~~
../../../../gittea/gcc/libcpp/expr.cc:845:38: error: format not a
string literal and no format arguments [-Werror=format-security]
845 | cpp_pedwarning_with_line (pfile, CPP_W_LONG_LONG,
| ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
846 | virtual_location, 0, message);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../../gittea/gcc/libcpp/expr.cc:855:33: error: format not a
string literal and no format arguments [-Werror=format-security]
855 | cpp_warning_with_line (pfile, CPP_W_SIZE_T_LITERALS,
| ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
856 | virtual_location, 0, message);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../../gittea/gcc/libcpp/expr.cc:867:42: error: format not a
string literal and no format arguments [-Werror=format-security]
867 | cpp_pedwarning_with_line (pfile, CPP_W_C11_C2X_COMPAT,
| ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
868 | virtual_location, 0, message);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../../gittea/gcc/libcpp/expr.cc:870:39: error: format not a
string literal and no format arguments [-Werror=format-security]
870 | cpp_warning_with_line (pfile, CPP_W_C11_C2X_COMPAT,
| ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
871 | virtual_location, 0, message);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../../gittea/gcc/libcpp/expr.cc:877:35: error: format not a
string literal and no format arguments [-Werror=format-security]
877 | cpp_error_with_line (pfile, CPP_DL_PEDWARN,
virtual_location, 0,
|
~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
878 | message);
| ~~~~~~~~
cc1plus: some warnings are being treated as errors
我感觉我错过了一些东西,因为这段代码 自 2012 年以来就没有再被碰过(感谢 git Blame) 所以我很确定我错过了一些东西,但不确定是什么。
我也在 nix-shell 中构建它,所以我的依赖项是
{
description = "gcc compiler";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let pkgs = nixpkgs.legacyPackages.${system};
in {
packages = {
default = pkgs.gnumake;
};
formatter = pkgs.nixpkgs-fmt;
devShell = pkgs.mkShell {
buildInputs = [
pkgs.gnumake
pkgs.gcc13
pkgs.libgcc
pkgs.glibc
pkgs.gmp
pkgs.libmpc
pkgs.mpfr
pkgs.flex
pkgs.bison
pkgs.isl
pkgs.pkg-config
pkgs.autoconf-archive
pkgs.autoconf
pkgs.automake
];
};
}
);
}
问题是 nix/NixOS 如何构建包!有关此问题的更多信息https://github.com/NixOS/nixpkgs/issues/18995
这花了我一段时间,但我在以下人员的帮助下发现了问题 一些海湾合作委员会大师。
nix 默认启用一些编译器标志,这可能会导致 对于那些使用低级东西的人来说,这是一段艰难的时光。
但是,解决方案非常简单。所有 Nix 用户都需要指定
hardeningDisable
。
就我而言,我只是禁用了薄片文件
hardeningDisable = [ "all" ];
完整解决方案
{
description = "gcc compiler";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let pkgs = nixpkgs.legacyPackages.${system};
in {
packages = {
default = pkgs.gnumake;
};
formatter = pkgs.nixpkgs-fmt;
devShell = pkgs.mkShell {
hardeningDisable = [ "all" ]; # Disable all hardening flags
buildInputs = [
pkgs.gnumake
pkgs.gcc13
pkgs.gmp
pkgs.libmpc
pkgs.mpfr
pkgs.flex
pkgs.bison
pkgs.isl
pkgs.pkg-config
pkgs.autoconf-archive
pkgs.autoconf
pkgs.automake
];
};
}
);
}