无法在archlinux上使用gcc构建llvm

icnyk63a  于 2022-11-13  发布在  Linux
关注(0)|答案(1)|浏览(174)

我试图构建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,也得到了同样的错误。
之后,我 checkout 到release/11.x分支,并尝试使用相同的cmake选项进行构建。然后构建步骤开始了,看起来很好。所以我尝试了另一个分支,release/13.xrelease/14.xrelease/15.x,它们都不起作用。
2:我的环境

$ 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

编辑:
我可以用gcc-9gcc-10在Ubuntu 20.04机器上构建release/12.x分支的llvm,所以我在这个问题上标记了archlinux
我也尝试了一些版本的c++标准,201714使用选项DCMAKE_CXX_STANDARD=,但它不会有帮助。

3htmauhk

3htmauhk1#

在我同事的帮助下,我能找到原因。
原因是-isystem /usr/bin/include选项。在我的笔记本电脑中,路径确实存在,但我不记得这是什么,pacmanparu也不知道...

相关问题