gpt4 book ai didi

c++ - 使用 arm-none-eabi 进行 Clang 交叉编译

转载 作者:行者123 更新时间:2023-11-28 04:27:50 27 4
gpt4 key购买 nike

我想对以下源文件(Foo.cpp)进行交叉编译

#include <cstdint>

int Foo()
{
uint32_t bar = 0;

return bar;
}

在 Windows 10 系统上使用 i686-w64-mingw32arm-none-eabi。因此我使用以下批处理文件

@echo off

set "PATH=C:/MinGW/i686-8.1.0-release-win32-dwarf-rt_v6-rev0/bin;%PATH%"
set "PATH=C:/GNU-Tools-ARM-Embedded/7-2018-q2-update/bin;%PATH%"
set "PATH=C:/LLVM/7.0.0/bin;%PATH%"

clang++ ^
-c ^
-std=gnu++14 ^
-v ^
-target i686-w64-mingw32 ^
Foo.cpp ^
-o Foo.obj

@echo on
REM
REM
REM
REM
REM
@echo off

clang++ ^
-c ^
-std=gnu++14 ^
-v ^
-target arm-none-eabi ^
-march=armv6-m ^
-mcpu=cortex-m0 ^
-mthumb ^
-msoft-float ^
-mfloat-abi=soft ^
--sysroot=C:/GNU-Tools-ARM-Embedded/7-2018-q2-update ^
Foo.cpp ^
-o Foo.o

pause

这会产生以下输出

clang version 7.0.0 (tags/RELEASE_700/final)
Target: i686-w64-windows-gnu
Thread model: posix
InstalledDir: C:\LLVM\7.0.0\bin
"C:\\LLVM\\7.0.0\\bin\\clang++.exe" -cc1 -triple i686-w64-windows-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name Foo.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -target-cpu pentium4 -dwarf-column-info -debugger-tuning=gdb -v -coverage-notes-file "c:\\Users\\Zlatan\\MKS\\Test\\Foo.gcno" -resource-dir "C:\\LLVM\\7.0.0\\lib\\clang\\7.0.0" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\i686-w64-mingw32\\include\\c++" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\i686-w64-mingw32\\include\\c++\\i686-w64-mingw32" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\i686-w64-mingw32\\include\\c++\\backward" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\i686-w64-mingw32\\include\\c++\\8.1.0" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\i686-w64-mingw32\\include\\c++\\8.1.0\\i686-w64-mingw32" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\i686-w64-mingw32\\include\\c++\\8.1.0\\backward" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\include\\c++\\8.1.0" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\include\\c++\\8.1.0\\i686-w64-mingw32" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\include\\c++\\8.1.0\\backward" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\lib\\gcc\\i686-w64-mingw32\\8.1.0\\include\\c++" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\lib\\gcc\\i686-w64-mingw32\\8.1.0\\include\\c++\\i686-w64-mingw32" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\lib\\gcc\\i686-w64-mingw32\\8.1.0\\include\\c++\\backward" -internal-isystem "C:\\LLVM\\7.0.0\\lib\\clang\\7.0.0\\include" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\i686-w64-mingw32/sys-root/mingw/include" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\i686-w64-mingw32\\include" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\include" -std=gnu++14 -fdeprecated-macro -fdebug-compilation-dir "c:\\Users\\Zlatan\\MKS\\Test" -ferror-limit 19 -fmessage-length 227 -fno-use-cxa-atexit -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdwarf-exceptions -fdiagnostics-show-option -fcolor-diagnostics -o Foo.obj -x c++ Foo.cpp
clang -cc1 version 7.0.0 based upon LLVM 7.0.0 default target x86_64-pc-win32
ignoring nonexistent directory "C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\i686-w64-mingw32\include\c++"
ignoring nonexistent directory "C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\i686-w64-mingw32\include\c++\i686-w64-mingw32"
ignoring nonexistent directory "C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\i686-w64-mingw32\include\c++\backward"
ignoring nonexistent directory "C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\i686-w64-mingw32\include\c++\8.1.0"
ignoring nonexistent directory "C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\i686-w64-mingw32\include\c++\8.1.0\i686-w64-mingw32"
ignoring nonexistent directory "C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\i686-w64-mingw32\include\c++\8.1.0\backward"
ignoring nonexistent directory "C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\include\c++\8.1.0"
ignoring nonexistent directory "C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\include\c++\8.1.0\i686-w64-mingw32"
ignoring nonexistent directory "C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\include\c++\8.1.0\backward"
ignoring nonexistent directory "C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\i686-w64-mingw32/sys-root/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\lib\gcc\i686-w64-mingw32\8.1.0\include\c++
C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\lib\gcc\i686-w64-mingw32\8.1.0\include\c++\i686-w64-mingw32
C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\lib\gcc\i686-w64-mingw32\8.1.0\include\c++\backward
C:\LLVM\7.0.0\lib\clang\7.0.0\include
C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\i686-w64-mingw32\include
C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\include
End of search list.

c:\Users\Zlatan\MKS\Test>REM

c:\Users\Zlatan\MKS\Test>REM

c:\Users\Zlatan\MKS\Test>REM

c:\Users\Zlatan\MKS\Test>REM

c:\Users\Zlatan\MKS\Test>REM
clang version 7.0.0 (tags/RELEASE_700/final)
Target: arm-none--eabi
Thread model: posix
InstalledDir: C:\LLVM\7.0.0\bin
"C:\\LLVM\\7.0.0\\bin\\clang++.exe" -cc1 -triple thumbv6m-none--eabi -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name Foo.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -mconstructor-aliases -nostdsysteminc -target-cpu cortex-m0 -target-feature +soft-float -target-feature +soft-float-abi -target-feature -crc -target-feature -dsp -target-feature -ras -target-feature -dotprod -target-feature -hwdiv-arm -target-feature -hwdiv -target-feature -fp-only-sp -target-feature -d16 -target-feature -vfp2 -target-feature -vfp3 -target-feature -fp16 -target-feature -vfp4 -target-feature -fp-armv8 -target-feature -neon -target-feature -crypto -target-feature +strict-align -target-abi aapcs -msoft-float -mfloat-abi soft -fallow-half-arguments-and-returns -dwarf-column-info -debugger-tuning=gdb -v -coverage-notes-file "c:\\Users\\Zlatan\\MKS\\Test\\Foo.gcno" -resource-dir "C:\\LLVM\\7.0.0\\lib\\clang\\7.0.0" -isysroot C:/GNU-Tools-ARM-Embedded/7-2018-q2-update -internal-isystem "C:/GNU-Tools-ARM-Embedded/7-2018-q2-update\\include\\c++\\v1" -internal-isystem "C:\\LLVM\\7.0.0\\lib\\clang\\7.0.0\\include" -internal-isystem "C:/GNU-Tools-ARM-Embedded/7-2018-q2-update\\include" -std=gnu++14 -fdeprecated-macro -fdebug-compilation-dir "c:\\Users\\Zlatan\\MKS\\Test" -ferror-limit 19 -fmessage-length 227 -fno-signed-char -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o Foo.o -x c++ Foo.cpp -faddrsig
clang -cc1 version 7.0.0 based upon LLVM 7.0.0 default target x86_64-pc-win32
ignoring nonexistent directory "C:/GNU-Tools-ARM-Embedded/7-2018-q2-update\include\c++\v1"
ignoring nonexistent directory "C:/GNU-Tools-ARM-Embedded/7-2018-q2-update\include"
ignoring duplicate directory "C:\LLVM\7.0.0\lib\clang\7.0.0\include"
#include "..." search starts here:
#include <...> search starts here:
C:\LLVM\7.0.0\lib\clang\7.0.0\include
End of search list.
Foo.cpp:1:10: fatal error: 'cstdint' file not found
#include <cstdint>
^~~~~~~~~
1 error generated.

所以对于i686-w64-mingw32,将编译器的位置放在路径中就足够了,但是对于arm-none-eabi,clang 编译器不能'找不到交叉编译头文件。

有人知道如何为 arm-none-eabi 配置 clang 吗?

为什么会出现下面的情况?

Target: arm-none--eabi

不应该吗?

Target: arm-none-eabi

谢谢!

兹拉坦

最佳答案

我参加聚会有点晚了,但无论如何,这是我的两分钱:

--sysroot 选项应该是:

--sysroot=C:/GNU-Tools-ARM-Embedded/7-2018-q2-update/arm-none-eabi

你错过了最后的 /arm-none-eabi 部分。 Clang 查找目录 binlibinclude,它们位于 arm-none-eabi 子目录中工具链(参见文档 here )。

这应该修复“忽略不存在的目录”错误和由于缺少标准库而导致的 fatal error 。

关于c++ - 使用 arm-none-eabi 进行 Clang 交叉编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53866650/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com