无法在 archlinux 上使用 gcc 构建 llvm



我试图构建llvm,但收到了一条与stdlib相关的错误消息
我搜索了带有错误消息的原因,但是我对c/c++不太了解,所以我不明白发生了什么,也不知道如何解决这个问题
请告诉我这意味着什么,以及在我的环境中发生了什么。

1:我所做的
我尝试使用以下内容构建llvm

git clone https://github.com/llvm/llvm-project -b release/12.x
cd llvm-project
mkdir build
cd build
cmake -G Ninja 
-DDEFAULT_SYSROOT=${HOME}/riscv_github/riscv64-unknown-elf 
-DCMAKE_BUILD_TYPE="Debug" 
-DLLVM_TARGETS_TO_BUILD="X86;AArch64;RISCV" 
-DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi" 
../llvm
ninja

并在下面收到一条错误消息。

[8/4685] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/ARMBuildAttrs.cpp.o
FAILED: lib/Support/CMakeFiles/LLVMSupport.dir/ARMBuildAttrs.cpp.o
/usr/bin/c++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/xxx/github.com/llvm-myriscvx120/build/lib/Support -I/home/xxx/github.com/llvm-myriscvx120/llvm/lib/Support -I/home/xxx/github.com/llvm-myriscvx120/build/include -I/home/xxx/github.com/llvm-myriscvx120/llvm/include -isystem /usr/bin/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wmisleading-indentation -fdiagnostics-color -g -std=c++14  -fno-exceptions -fno-rtti -MD -MT lib/Support/CMakeFiles/LLVMSupport.dir/ARMBuildAttrs.cpp.o -MF lib/Support/CMakeFiles/LLVMSupport.dir/ARMBuildAttrs.cpp.o.d -o lib/Support/CMakeFiles/LLVMSupport.dir/ARMBuildAttrs.cpp.o -c /home/xxx/github.com/llvm-myriscvx120/llvm/lib/Support/ARMBuildAttrs.cpp
In file included from /usr/include/c++/12.1.1/cstdlib:75,
from /usr/include/c++/12.1.1/bits/stl_algo.h:69,
from /usr/include/c++/12.1.1/algorithm:61,
from /home/xxx/github.com/llvm-myriscvx120/llvm/include/llvm/ADT/Hashing.h:51,
from /home/xxx/github.com/llvm-myriscvx120/llvm/include/llvm/ADT/ArrayRef.h:12,
from /home/xxx/github.com/llvm-myriscvx120/llvm/include/llvm/Support/ELFAttributes.h:12,
from /home/xxx/github.com/llvm-myriscvx120/llvm/include/llvm/Support/ARMBuildAttributes.h:21,
from /home/xxx/github.com/llvm-myriscvx120/llvm/lib/Support/ARMBuildAttrs.cpp:9:
/usr/include/stdlib.h:579:5: error: expected initializer before ‘__attr_dealloc_free’
579 |     __attr_dealloc_free;
|     ^~~~~~~~~~~~~~~~~~~
/usr/include/stdlib.h:583:14: error: expected initializer before ‘__attr_dealloc’
583 |      __THROW __attr_dealloc (reallocarray, 1);
|              ^~~~~~~~~~~~~~
/usr/include/stdlib.h:606:35: error: expected initializer before ‘__attribute_alloc_align__’
606 |      __THROW __attribute_malloc__ __attribute_alloc_align__ ((1))
|                                   ^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/stdlib.h:812:6: error: expected initializer before ‘__attr_dealloc_free’
812 |      __attr_dealloc_free __wur;
|      ^~~~~~~~~~~~~~~~~~~
/usr/include/stdlib.h:961:3: error: expected initializer before ‘__fortified_attr_access’
961 |   __fortified_attr_access (__write_only__, 1, 3)
|   ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/stdlib.h:1016:30: error: expected initializer before ‘__fortified_attr_access’
1016 |      __THROW __nonnull ((2)) __fortified_attr_access (__write_only__, 2, 3);
|                              ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/12.1.1/cstdlib:171:11: error: ‘wcstombs’ has not been declared in ‘::’
171 |   using ::wcstombs;
|           ^~~~~~~~
ninja: build stopped: subcommand failed.

在我看来,gcc好像坏了,所以我尝试用gcc-11(g++-11)gcc-10(g++-10)构建llvm,但得到了同样的错误。

之后,我签出到release/11.x分支,并尝试使用相同的cmake选项进行构建。然后构建步骤开始了,看起来很好。所以我尝试了另一个分支,release/13.xrelease/14.xrelease/15.x,但它们都不起作用。

2:My Env

$ uname -a
Linux arch-x13 5.18.16-arch1-1 #1 SMP PREEMPT_DYNAMIC Wed, 03 Aug 2022 11:25:04 +000 x86_64 GNU/Linux
$ gcc --version
gcc (GCC) 12.1.1 20220730
Copyright (C) 2022 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.
$ cmake --version
cmake version 3.23.3
CMake suite maintained and supported by Kitware (kitware.com/cmake).**strong text**
$ ninja --version
1.11.0

编辑:
我可以在Ubuntu20.4机器上用gcc-9gcc-10构建release/12.x分支的llvm,所以我将archlinux标记为这个问题。

我还尝试了一些版本的c++标准,201714,使用选项DCMAKE_CXX_STANDARD=,但没有帮助。

在同事的帮助下,我可以找到原因
原因是-isystem /usr/bin/include选项。在我的笔记本电脑里,这条路肯定存在,但我不记得这是什么,pacmanparu都不知道。。。

最新更新