本文介绍了使用 llvm 从桌面到 arm 进行交叉编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在笔记本电脑上编写 c 代码,我想使用 llvm-clang 工具链将其交叉编译为 ARM v7 架构.

I am writing c code on my laptop and I would like to cross compile it to ARM v7 architecture using the llvm-clang toolchain.

我正在关注这个网站 http://llvm.org/docs/HowToCrossCompileLLVM.html使用这个命令来配置cmake:

I am following this website http://llvm.org/docs/HowToCrossCompileLLVM.html using this command to configure cmake:

我正在使用以下命令并收到以下错误(见下文).知道出了什么问题吗?

I am using the following command and getting the following errors (see below). Any idea what is wrong?

谢谢

-------------------------------开始---------------------------------------------

-------------------------------START----------------------------------------------

cmake -G Ninja/home/user/Desktop/llvm/llvm -DCMAKE_CROSSCOMPILING=True -DCMAKE_INSTALL_PREFIX=/home/user/Desktop/llvm/llvm/new_build -DLLVM_TABLEGEN=/usr/bin/host/llvm-tblgen -DCLANG_TABLEGEN=/usr/bin/host/clang-tblgen -DLLVM_DEFAULT_TARGET_TRIPLE=arm-linux-gnueabihf -DLLVM_TARGET_ARCH=ARM -DLLVM_TARGETS_TO_BUILD=ARM -DCMAKE_CXX_FLAGS='-target tex armv7a-linux-usrmpua9arm-linux-gnueabihf/include/c++/4.7.2/arm-linux-gnueabihf/-I/usr/arm-linux-gnueabihf/include/-mfloat-abi=hard -ccc-gcc-name arm-linux-gnueabihf-gcc'

cmake -G Ninja /home/user/Desktop/llvm/llvm -DCMAKE_CROSSCOMPILING=True -DCMAKE_INSTALL_PREFIX=/home/user/Desktop/llvm/llvm/new_build -DLLVM_TABLEGEN=/usr/bin/host/llvm-tblgen -DCLANG_TABLEGEN=/usr/bin/host/clang-tblgen -DLLVM_DEFAULT_TARGET_TRIPLE=arm-linux-gnueabihf -DLLVM_TARGET_ARCH=ARM -DLLVM_TARGETS_TO_BUILD=ARM -DCMAKE_CXX_FLAGS='-target armv7a-linux-gnueabihf -mcpu=cortex-a9 -I/usr/arm-linux-gnueabihf/include/c++/4.7.2/arm-linux-gnueabihf/ -I/usr/arm-linux-gnueabihf/include/ -mfloat-abi=hard -ccc-gcc-name arm-linux-gnueabihf-gcc'

------------------------------END-------------------------------------------------

------------------------------END-------------------------------------------------

错误:

-------------------------------开始---------------------------------------------

-------------------------------START----------------------------------------------

-- CXX 编译器标识为 Clang 3.5.0-- 检查工作 CXX 编译器使用:忍者-- 检查工作 CXX 编译器使用:忍者 -- 损坏/usr/share/cmake-2.8/Modules/CMakeTestCXXCompiler.cmake:54 处的 CMake 错误(消息):C++编译器/usr/bin/clang++"无法编译一个简单的测试程序.

-- The CXX compiler identification is Clang 3.5.0-- Check for working CXX compiler using: Ninja-- Check for working CXX compiler using: Ninja -- brokenCMake Error at /usr/share/cmake-2.8/Modules/CMakeTestCXXCompiler.cmake:54 (message): The C++ compiler "/usr/bin/clang++" is not able to compile a simple test program.

失败,输出如下:

更改目录:/home/user/Desktop/llvm/llvm/new_build/CMakeFiles/CMakeTmp

Change Dir: /home/user/Desktop/llvm/llvm/new_build/CMakeFiles/CMakeTmp

运行构建命令:/usr/bin/ninja cmTryCompileExec1541562247

Run Build Command:/usr/bin/ninja cmTryCompileExec1541562247

[1/2] 构建 CXX 对象

[1/2] Building CXX object

CMakeFiles/cmTryCompileExec1541562247.dir/testCXXCompiler.cxx.o

CMakeFiles/cmTryCompileExec1541562247.dir/testCXXCompiler.cxx.o

[2/2] 链接 CXX 可执行文件 cmTryCompileExec1541562247

[2/2] Linking CXX executable cmTryCompileExec1541562247

失败::&&/usr/bin/clang++ -target armv7a-linux-gnueabihf

FAILED: : && /usr/bin/clang++ -target armv7a-linux-gnueabihf

-mcpu=cortex-a9

-mcpu=cortex-a9

-I/usr/arm-linux-gnueabihf/include/c++/4.7.2/arm-linux-gnueabihf/

-I/usr/arm-linux-gnueabihf/include/c++/4.7.2/arm-linux-gnueabihf/

-I/usr/arm-linux-gnueabihf/include/-mfloat-abi=hard -ccc-gcc-name

-I/usr/arm-linux-gnueabihf/include/ -mfloat-abi=hard -ccc-gcc-name

arm-linux-gnueabihf-gcc

arm-linux-gnueabihf-gcc

CMakeFiles/cmTryCompileExec1541562247.dir/testCXXCompiler.cxx.o -o

CMakeFiles/cmTryCompileExec1541562247.dir/testCXXCompiler.cxx.o -o

cmTryCompileExec1541562247 -rdynamic &&:

cmTryCompileExec1541562247 -rdynamic && :

/usr/bin/ld: 无法识别的仿真模式:armelf_linux_eabi

/usr/bin/ld: unrecognised emulation mode: armelf_linux_eabi

支持的仿真:elf_x86_64 elf32_x86_64 elf_i386 i386linux elf_l1om

Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 i386linux elf_l1om

elf_k1om i386pep i386pe

elf_k1om i386pep i386pe

clang: 错误:链接器命令失败,退出代码为 1(使用 -v 查看

clang: error: linker command failed with exit code 1 (use -v to see

调用)

ninja:构建停止:子命令失败.

ninja: build stopped: subcommand failed.

CMake 将无法正确生成此项目.

CMake will not be able to correctly generate this project.

调用堆栈(最近的调用在前):

Call Stack (most recent call first):

CMakeLists.txt:19(项目)

CMakeLists.txt:19 (project)

-- 配置不完整,出现错误!

-- Configuring incomplete, errors occurred!

------------------------------END-------------------------------------------------

------------------------------END-------------------------------------------------

推荐答案

您使用了错误的指南.

您链接的网页是关于如何使用 LLVM 和 Clang 交叉编译 LLVM 和 Clang 的指南.但是您不想编译 LLVM 本身,您只想使用它.指南是:http://clang.llvm.org/docs/CrossCompilation.html

The web page you linked is a guide on how to cross-compile LLVM and Clang using LLVM and Clang. But you don't want to compile LLVM itself, you only want to use it. The guide for that is: http://clang.llvm.org/docs/CrossCompilation.html

这篇关于使用 llvm 从桌面到 arm 进行交叉编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!