用arm-none-eabi进行交叉编译
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用arm-none-eabi进行交叉编译相关的知识,希望对你有一定的参考价值。
我想做以下源文件的交叉编译(Foo.cpp)
#include <cstdint>
int Foo()
uint32_t bar = 0;
return bar;
在Windows 10系统上使用i686-w64-mingw32和arm-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吗?
为什么会发生以下情况?
目标:arm-none - eabi
不应该吗?
目标:arm-none-eabi
谢谢!
伊布拉希莫
答案
我参加派对有点晚了,但不管怎么说,这是我的两分钱:
--sysroot
选项应该是:
--sysroot=C:/GNU-Tools-ARM-Embedded/7-2018-q2-update/arm-none-eabi
你最后错过了/arm-none-eabi
部分。 Clang查找工具链的bin
子目录中的目录lib
,include
和arm-none-eabi
(参见文档here)。
这应该修复“忽略不存在的目录”错误和由于缺少标准库而导致的致命错误。
以上是关于用arm-none-eabi进行交叉编译的主要内容,如果未能解决你的问题,请参考以下文章