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

时间:2018-12-20 10:18:57

标签: c++ arm clang cross-compiling

我想对以下源文件(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吗?

为什么会发生以下情况?

  

目标:不留神-eabi

不是吗?

  

目标:arm-none-eabi

谢谢!

Zlatan

1 个答案:

答案 0 :(得分:1)

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

# get the column names that start with 'X__' nms <- names(dt)[startsWith(names(dt), "X__")] # change the i index with cumulative sum for(j in nms) set(dt, i = which(cumsum(!is.na(dt[[j]])) == 0), j = j, value = "-") 选项应为:

--sysroot

您最后缺少--sysroot=C:/GNU-Tools-ARM-Embedded/7-2018-q2-update/arm-none-eabi 部分。 Clang在工具链的/arm-none-eabi子目录中查找目录binlibinclude(请参见文档here)。

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