Clang Cross使用Yocto SDK进行编译

时间:2016-02-02 22:12:00

标签: clang cross-compiling llvm-clang yocto

是否可以使用Yocto SDK中的工具链和sysroot与Clang / LLVM for ARM进行交叉编译?

Yocto SDK中的环境设置脚本具有以下编译器选项:

export CC="arm-poky-linux-gnueabi-gcc  -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=$SDKTARGETSYSROOT"

我想交叉编译这个简单的用户空间应用程序

testapp.c:

#include <stdio.h>
int main()
   {
   printf("Hello World\n");
   return(0);
   }

按照指南http://clang.llvm.org/docs/CrossCompilation.html,我试图用

交叉编译应用程序
$ GCCFLAGS="-mcpu=cortex-a7 -mfpu=neon -mfloat-abi=hard"
$ GCCINCLUDE="/opt/poky/2.0.1/sysroots/cortexa7hf-vfp-neon-poky-linux-gnueabi/usr/include/c++/5.2.0/arm-poky-linux-gnueabi/

$ /usr/bin/clang -target arm-poky-linux-gnueabi $GCCFLAGS -I$GCCINCLUDE -ccc-gcc-name arm-poky-linux-gnueabi-gcc testapp.c -o testapp -v

但是,

失败了
Ubuntu clang version 3.4.2-3ubuntu2~xedgers (tags/RELEASE_34/dot2-final) (based on LLVM 3.4.2)
Target: arm-poky-linux-gnueabi
Thread model: posix
Selected GCC installation: 
 "/usr/lib/llvm-3.4/bin/clang" -cc1 -triple armv7-poky-linux-gnueabi -S -disable-free -disable-llvm-verifier -main-file-name testapp.c -mrelocation-model static -mdisable-fp-elim -fmath-errno -mconstructor-aliases -target-cpu cortex-a7 -target-feature +neon -target-abi aapcs-linux -mfloat-abi hard -target-linker-version 2.24 -v -resource-dir /usr/lib/llvm-3.4/bin/../lib/clang/3.4.2 -I /opt/poky/2.0.1/sysroots/cortexa7hf-vfp-neon-poky-linux-gnueabi/usr/include/c++/5.2.0/arm-poky-linux-gnueabi/ -internal-isystem /usr/include/clang/3.4.2/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-3.4/bin/../lib/clang/3.4.2/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fno-dwarf-directory-asm -fdebug-compilation-dir /home/adtec/workspace/yocto/testapp -ferror-limit 19 -fmessage-length 207 -mstackrealign -fno-signed-char -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o /tmp/testapp-8517af.s -x c testapp.c
clang -cc1 version 3.4.2 based upon LLVM 3.4.2 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/include"
ignoring duplicate directory "/usr/include/clang/3.4.2/include"
#include "..." search starts here:
#include <...> search starts here:
 /opt/poky/2.0.1/sysroots/cortexa7hf-vfp-neon-poky-linux-gnueabi/usr/include/c++/5.2.0/arm-poky-linux-gnueabi
 /usr/include/clang/3.4.2/include
 /usr/local/include
 /usr/include
End of search list.
'cortex-a7' is not a recognized processor for this target (ignoring processor)
'cortex-a7' is not a recognized processor for this target (ignoring processor)
'cortex-a7' is not a recognized processor for this target (ignoring processor)
'cortex-a7' is not a recognized processor for this target (ignoring processor)
'cortex-a7' is not a recognized processor for this target (ignoring processor)
'cortex-a7' is not a recognized processor for this target (ignoring processor)
 "/usr/bin/as" -mfloat-abi=hard -mcpu=cortex-a7 -mfpu=neon -o /tmp/testapp-f4f688.o /tmp/testapp-8517af.s
/usr/bin/as: unrecognized option '-mfloat-abi=hard'
clang: error: assembler command failed with exit code 1 (use -v to see invocation)

为ARM交叉编译这个简单的应用程序需要什么样的Clang标志?

2 个答案:

答案 0 :(得分:1)

如果您可以访问完整版本而不仅仅是SDK,则可以尝试使用clang图层https://github.com/kraj/meta-clang。虽然最终可能会构建一个包含clang的SDK,但我认为还没有人这样做过。

答案 1 :(得分:0)

您可以使用meta-clang并生成包含基于gcc和clang的交叉编译器的SDK,一旦安装了SDK,CLANGCC和CLANGCXX环境变​​量就可以调用clang而不是gcc。如果您想将其用作默认设置,则可以

export CC=${CLANGCC}
export CXX=${CLANGCXX}
export CPP=${CLANGCPP}

还有Clang SDK here

的写作