【发布时间】:2021-12-03 21:35:29
【问题描述】:
我正在尝试使用 GNU ARM Embedded Toolchain 库和 Clang 编译器交叉编译 C++ 目标文件。我无法理解成功编译缺少什么。谁能帮我理解一下为什么clang找不到头文件?
这是我的示例程序:
#include <algorithm>
extern "C" uint32_t * copy(
uint32_t const * first, uint32_t const * last, uint32_t * dest)
{
return std::copy(first, last, dest);
}
我通过指定目标和 sysroot 来调用 clang++:
$ clang++ --target=thumbv7m-none-eabi --sysroot "C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.07\arm-none-eabi" -c example.cpp -v
clang version 12.0.1
Target: thumbv7m-none-unknown-eabi
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
(in-process)
"C:\\Program Files\\LLVM\\bin\\clang++.exe" -cc1 -triple thumbv7m-none-unknown-eabi -emit-obj -mrelax-all --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name example.cpp -mrelocation-model static -mframe-pointer=all -fmath-errno -fno-rounding-math -fno-verbose-asm -mconstructor-aliases -nostdsysteminc -target-cpu cortex-m3 -target-feature +soft-float-abi -target-feature +strict-align -target-abi aapcs -mfloat-abi soft -fallow-half-arguments-and-returns -fno-split-dwarf-inlining -debugger-tuning=gdb -v -resource-dir "C:\\Program Files\\LLVM\\lib\\clang\\12.0.1" -isysroot "C:\\Program Files (x86)\\GNU Arm Embedded Toolchain\\10 2021.07\\arm-none-eabi" -internal-isystem "C:\\Program Files (x86)\\GNU Arm Embedded Toolchain\\10 2021.07\\arm-none-eabi\\include\\c++\\v1" -internal-isystem "C:\\Program Files\\LLVM\\lib\\clang\\12.0.1\\include" -internal-isystem "C:\\Program Files (x86)\\GNU Arm Embedded Toolchain\\10 2021.07\\arm-none-eabi\\include" -fdeprecated-macro -fdebug-compilation-dir "C:\\source\\espresso\\components" -ferror-limit 19 -fmessage-length=226 -fno-signed-char -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -o example.o -x c++ example.cpp
clang -cc1 version 12.0.1 based upon LLVM 12.0.1 default target x86_64-pc-windows-msvc
ignoring nonexistent directory "C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.07\arm-none-eabi\include\c++\v1"
ignoring duplicate directory "C:\Program Files\LLVM\lib\clang\12.0.1\include"
#include "..." search starts here:
#include <...> search starts here:
C:\Program Files\LLVM\lib\clang\12.0.1\include
C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.07\arm-none-eabi\include
End of search list.
example.cpp:3:10: fatal error: 'algorithm' file not found
#include <algorithm>
^~~~~~~~~~~
1 error generated.
我怀疑是链接器错误(clang 可能不知道如何在 sysroot 中找到正确的库),但令我惊讶的是,clang 无法在给定 sysroot 的情况下推断算法头的位置。
有什么建议吗?
clang 和 arm-none-eabi-gcc 都在我的路径中:
$ clang++ --version
clang version 12.0.1
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Arm Embedded Toolchain 10.3-2021.07) 10.3.1 20210621 (release)
Copyright (C) 2020 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.
【问题讨论】:
标签: c++ c arm clang cross-compiling