从源代码为 ARM 交叉编译 Qt 4.7 的问题 [英] Problems cross compiling Qt 4.7 from source for ARM

查看:38
本文介绍了从源代码为 ARM 交叉编译 Qt 4.7 的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从源代码交叉编译 Qt 4.7.1,以下是关于我的设置的一些注意事项:

I'm trying to cross-compile Qt 4.7.1 from source, here are some notes on my setup:

  1. 我的预期输出是运行 Qt 应用程序所需的共享对象库.
  2. 我的目标平台是采用 ARM Cortex-A8 架构的 TI AM335x 处理器.
  3. 我的开发平台是 x86 64 位 Ubuntu 虚拟机

我对这应该如何工作的理解是我为我的目标平台下载了工具链(这是 Linaro 工具链来自 TI),我下载了 Qt 的源代码4.7.1,我设置mkspec使用我的工具链,运行configure,然后只需要运行make/make install 我应该能够找到我告诉它安装到的所有 .so.然而,我在让这个想法发挥作用时遇到了很多问题.

My understanding of how this should work is that I download the toolchain for my target platform (this is the Linaro toolchain from TI), I download the source code for Qt 4.7.1, I set the mkspec to use my tool chain, run configure, then just need to run make/make install and I should be able to find all the .so's where I told it to install to. I'm having a lot of problems getting this idea to work however.

首先我下载了​​ TI SDK 版本:ti-sdk-am335x-evm-06.00.00.00,它的 arm 工具位于:[root_install_dir]/linux-devkit/sysroots/i686-arago-linux/usr/bin

First I downloaded the TI SDK version: ti-sdk-am335x-evm-06.00.00.00 which has the arm tool's at: [root_install_dir]/linux-devkit/sysroots/i686-arago-linux/usr/bin

我用那个目录更新了我的 $PATH:

I updated my $PATH with that directory:

mike@mike-VirtualBox:~$ echo $PATH/home/mike/ti-sdk-am335x-evm-06.00.00.00/linux-devkit/sysroots/i686-arago-linux/usr/bin:/usr/local/Trolltech/Qt-4.8.5/bin:/home/mike/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/mike/bin

mike@mike-VirtualBox:~$ echo $PATH /home/mike/ti-sdk-am335x-evm-06.00.00.00/linux-devkit/sysroots/i686-arago-linux/usr/bin :/usr/local/Trolltech/Qt-4.8.5/bin:/home/mike/bin:/usr/lib/lightdm/lightdm: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/mike/bin

然后我根据最接近的示例创建了自己的 mkspec:cp -R [qt_install_dir]/mkspecs/qws/linux-arm-gnueabi-g++/[qt_install_dir]/mkspecs/qws/linux-am335x-g++

I then created my own mkspec based on the closest example: cp -R [qt_install_dir]/mkspecs/qws/linux-arm-gnueabi-g++/ [qt_install_dir]/mkspecs/qws/linux-am335x-g++

我修改了 linux-am335x-g++/qmake.conf 以指向来自 TI sdk 的工具:

and I modified the linux-am335x-g++/qmake.conf to point to the tools from the TI sdk:

# modifications to g++.conf
QMAKE_CC                = arm-linux-gnueabihf-gcc
QMAKE_CXX               = arm-linux-gnueabihf-g++
QMAKE_LINK              = arm-linux-gnueabihf-g++
QMAKE_LINK_SHLIB        = arm-linux-gnueabihf-g++

# modifications to linux.conf
QMAKE_AR                = arm-linux-gnueabihf-ar cqs
QMAKE_OBJCOPY           = arm-linux-gnueabihf-objcopy
QMAKE_STRIP             = arm-linux-gnueabihf-strip

然后我运行了一个配置命令:

Then I ran a configure command:

./configure -prefix/home/mike/qt4.7.1_source/my_qt -embedded arm -platform qws/linux-x86_64-g++ -xplatform qws/linux-am335x-g++ -no-mmx -no-3dnow -no-sse -no-sse2 -no-glib -no-cups -no-largefile -no-accessibility -no-openssl -no-gtkstyle -fast -opensource

./configure -prefix /home/mike/qt4.7.1_source/my_qt -embedded arm -platform qws/linux-x86_64-g++ -xplatform qws/linux-am335x-g++ -no-mmx -no-3dnow -no-sse -no-sse2 -no-glib -no-cups -no-largefile -no-accessibility -no-openssl -no-gtkstyle -fast -opensource

它运行了一段时间然后完成并说它已准备好执行 make/make install 此时我运行 make 这就是它开始失败:

It runs for a while then completes and says it's ready to do make/make install at this point I run make and that's where it starts to fail:

/home/mike/qt4.7.1_source/qt-everywhere-opensource-src-4.7.1/bin/moc-DQT_SHARED -DQT_BUILD_CORE_LIB -DQT_NO_USING_NAMESPACE -DQT_NO_CAST_TO_ASCII -DQT_ASCII_CAST_WARNINGS -DQT3_SUPPORT -DQT_MOC_COMPAT -DQT_USE_FAST_OPERATOR_PLUS -DQT_USE_FAST_CONCATENATION -DELF_INTERPRETER = /lib64下/LD-Linux的x86-64.so.2 " -DHB_EXPORT = Q_CORE_EXPORT -DQT_HAVE_NEON -DQT_NO_DEBUG -I../../mkspecs/qws/linux-am335x-g++ -I.-I../../include -I../../include/QtCore -I.rcc/release-shared-emb-arm -Iglobal -I../3rdparty/harfbuzz/src -I../3rdparty/md5 -I../3rdparty/md4 -I.moc/release-shared-emb-arm kernel/qobject.h -o .moc/release-shared-emb-arm/moc_qobject.cpp arm-linux-gnueabihf-g++-C-include .pch/release-shared-emb-arm/QtCore -pipe -fno-exceptions -mfpu=neon -O2 -fvisibility=hidden -fvisibility-inlines-hidden -Wall -W -D_REENTRANT -fPIC -DQT_SHARED -DQT_BUILD_CORE_LIB -DQT_NO_USING_NAMESPACE-DQT_NO_CAST_TO_ASCII -DQT_ASCII_CAST_WARNINGS -DQT3_SUPPORT -DQT_MOC_COMPAT -DQT_USE_FAST_OPERATOR_PLUS -DQT_USE_FAST_CONCATENATION -DELF_INTERPRETER = /lib64下/LD-Linux的x86-64.so.2 " -DHB_EXPORT = Q_CORE_EXPORT -DQT_HAVE_NEON -DQT_NO_DEBUG -I ../../mkspecs/qws/linux-am335x-g++ -I.-I../../include -I../../include/QtCore -I.rcc/release-shared-emb-arm -Iglobal -I../3rdparty/harfbuzz/src -I../3rdparty/md5 -I../3rdparty/md4 -I.moc/release-shared-emb-arm -o .obj/release-shared-emb-arm/qobject.o kernel/qobject.cpp
{标准输入}: 汇编器消息:
{标准输入}:1294: 错误:所选处理器不支持 Thumb 模式 'swp r6,r4,[r3]'
ma​​ke[1]: [.obj/release-shared-emb-arm/qobject.o] 错误 1*
make[1]: 离开目录
'/home/mike/qt4.7.1_source/qt-everywhere-opensource-src-4.7.1/src/corelib'
make: * [sub-corelib-make_default-ordered] 错误 2

/home/mike/qt4.7.1_source/qt-everywhere-opensource-src-4.7.1/bin/moc -DQT_SHARED -DQT_BUILD_CORE_LIB -DQT_NO_USING_NAMESPACE -DQT_NO_CAST_TO_ASCII -DQT_ASCII_CAST_WARNINGS -DQT3_SUPPORT -DQT_MOC_COMPAT -DQT_USE_FAST_OPERATOR_PLUS -DQT_USE_FAST_CONCATENATION -DELF_INTERPRETER="/lib64/ld-linux-x86-64.so.2" -DHB_EXPORT=Q_CORE_EXPORT -DQT_HAVE_NEON -DQT_NO_DEBUG -I../../mkspecs/qws/linux-am335x-g++ -I. -I../../include -I../../include/QtCore -I.rcc/release-shared-emb-arm -Iglobal -I../3rdparty/harfbuzz/src -I../3rdparty/md5 -I../3rdparty/md4 -I.moc/release-shared-emb-arm kernel/qobject.h -o .moc/release-shared-emb-arm/moc_qobject.cpp arm-linux-gnueabihf-g++ -c -include .pch/release-shared-emb-arm/QtCore -pipe -fno-exceptions -mfpu=neon -O2 -fvisibility=hidden -fvisibility-inlines-hidden -Wall -W -D_REENTRANT -fPIC -DQT_SHARED -DQT_BUILD_CORE_LIB -DQT_NO_USING_NAMESPACE -DQT_NO_CAST_TO_ASCII -DQT_ASCII_CAST_WARNINGS -DQT3_SUPPORT -DQT_MOC_COMPAT -DQT_USE_FAST_OPERATOR_PLUS -DQT_USE_FAST_CONCATENATION -DELF_INTERPRETER="/lib64/ld-linux-x86-64.so.2" -DHB_EXPORT=Q_CORE_EXPORT -DQT_HAVE_NEON -DQT_NO_DEBUG -I../../mkspecs/qws/linux-am335x-g++ -I. -I../../include -I../../include/QtCore -I.rcc/release-shared-emb-arm -Iglobal -I../3rdparty/harfbuzz/src -I../3rdparty/md5 -I../3rdparty/md4 -I.moc/release-shared-emb-arm -o .obj/release-shared-emb-arm/qobject.o kernel/qobject.cpp
{standard input}: Assembler messages:
{standard input}:1294: Error: selected processor does not support Thumb mode 'swp r6,r4,[r3]'
make[1]: [.obj/release-shared-emb-arm/qobject.o] Error 1*
make[1]: Leaving directory
'/home/mike/qt4.7.1_source/qt-everywhere-opensource-src-4.7.1/src/corelib'
make: * [sub-corelib-make_default-ordered] Error 2

所以,问题...为什么编译器抱怨不支持拇指模式?由于这是基于 ARM 的处理器的交叉编译工具链,因此应该支持它.事实上,它不是让我觉得 make 以某种方式选择了错误的 g++ 版本.

So, the question... Why is the compiler complaining that the thumb mode is not supported? Since this is a cross compile tool chain for an ARM based processor, it should be supported. The fact that it's not makes me feel that make is somehow picking up the wrong version of g++.

对出了什么问题以及如何解决此问题有任何想法吗?

Any thoughts on what went wrong and how to fix this?

推荐答案

{标准输入}:1294: 错误:所选处理器不支持 Thumb 模式 'swp r6,r4,[r3]'

为什么编译器会抱怨不支持拇指模式?

Why is the compiler complaining that the thumb mode is not supported?

注意,编译器抱怨 swp 指令不适用于 thumb 模式.您的 CPU 支持 thumbthumb2ARM.Cortex 系列不赞成使用 swp 并且更喜欢 ldrex/strex 对.

Note, the compiler is complaining about the swp instruction not being available for thumb mode. Your CPU supports thumb, thumb2, and ARM. The Cortex series deprecates the use of swp and prefers ldrex/strex pairs.

对出了什么问题以及如何解决此问题有任何想法吗?

Any thoughts on what went wrong and how to fix this?

你需要得到gcc来定义__ARM_ARCH_7__;这是通过 -mcpu=cortex-a8 或组合 -mtune=cortex-a8-march=armv7-a 或什么取决于您希望 Qt 在多少种类型的板上运行.

You need to get gcc to define __ARM_ARCH_7__; this is done with either -mcpu=cortex-a8 or the combination -mtune=cortex-a8 and -march=armv7-a or what ever you like depending on how many types of boards you want Qt to run on.

详细请参见qatomic_arm.h 用于选择子文件的位置.你有一个非常通用的 ARM 选择(我猜),所以你得到 qatomic_armv5.hNote1 你可以在第 125 行看到代码.适合你的 CPU 的正确文件是qatomic_armv7.h,主要只包含qatomic_armv6.h.在这个文件中,您可以找到 ldrex/strex,这是您的 gcc 所要求的有益健康.

In detail, see qatomic_arm.h for where a sub-file is selected. You have a very generic ARM selected (I guess), so you get qatomic_armv5.hNote1 where you can see the code around line 125. The right file for your CPU is qatomic_armv7.h, which mainly just includes qatomic_armv6.h. In this file you can find ldrex/strex which is the wholesome goodness that your gcc is requesting.

我也建议你不要用-fast编译.OP 说 another question这解决了他的问题;但我认为这是不同的.

I also suggest you do not compile with -fast. There is another question where the OP says this solved his issue; but I think this is different.

你可以尝试通过-armfpa来配置../configure -embedded arm --help 很有用.configure 似乎选择了 NEON,所以它似乎知道你有更高级的 CPU(armv5 上没有 NEON,但这可能是 configure 的错误).

You can try to pass -armfpa to configure. ./configure -embedded arm --help is useful. configure appears to have selected NEON, so it seems to know you have a more advanced CPU (there is no NEON on an armv5, but this maybe a fault of configure).

当然,您不想要 swp 代码,而 ldrex/strex 是您系统的首选,即使 swp 可以以某种方式工作.我至少会解决这个问题.更改 -xplatform qws/linux-am335x-g++ 以更新 -mcpu 或可能传递显式 -D__ARM_ARCH_7__.您可以使用 arm-gcc -mcpu=cortex-a8 -dM -E 获取定义列表- ,验证 __ARM_ARCH_7__ 是否被定义.看起来它是 moc 失败,所以可能需要 -D__ARM_ARCH_7_ 解决方案.

For certain, you don't want the swp code and the ldrex/strex is preferred for your system, even if swp could somehow work. I would at least resolve this. Alter the -xplatform qws/linux-am335x-g++ to update -mcpu or possibly pass an explicit -D__ARM_ARCH_7__. You can get a list of defines with arm-gcc -mcpu=cortex-a8 -dM -E - < /dev/null, to verify that the __ARM_ARCH_7__ is being defined. It looks like it is moc failing, so maybe the -D__ARM_ARCH_7_ solution will be needed.

您也可以尝试更改编译器选项中的 -mthumb.如果可以编译/构建,最好为您的系统使用 -mcpu=cortex-a8-mthumb.省略 -mthumb 会使代码略大.你也可以试试-Os.出于某种原因,我有 huge 构建了其他优化和更新的 gcc 版本.这似乎是由于某些 C++ 特性,因为普通的C"不是这样的;但这可能只是我的编译器.我查看并相信这是异常表,但我从未确认任何内容并继续前进.我相信您知道 Qt 编译需要多长时间.

You might also try to alter -mthumb in the compiler option. It is probably best to use -mcpu=cortex-a8 and -mthumb for your system, if you can get that to compile/build. Omitting -mthumb will make the code slightly larger. You might also try -Os. For some reason, I have huge builds with other optimizations and more recent gcc versions. It appears to be due to some C++ feature as normal 'C' doesn't behave this way; but this may just be my compiler. I looked and believe it is the exception tables, but I never confirmed anything and moved on. I am sure you are aware of how long Qt takes to compile.

注意1: qatomic_armv5.h 代码相当混乱,更新的 gccbinutils 即使在这是要使用的正确文件.

Note1: The qatomic_armv5.h code is fairly confused and newer gcc or binutils will choke even when this is the correct file to use.

 asm volatile("swpb %0,%2,[%3]"
: "=&r"(ret), "=m" (*ptr)
: "r"(newval), "r"(ptr)
: "cc", "memory");

这指定了一些从不使用的内联汇编器参数.更不用说没有使用条件码等等.

This specifies some inline assembler parameters which are never used. Not to mention the condition codes are not used, etc.

asm volatile("swpb %0,%1,[%2]"
             : "=r"(ret)
             : "0"(newval), "r"(ptr)
             : "memory");

将使用更新的 gccbinutils 进行编译.它还使用较少的寄存器,并且最适合 Qt 当前使用它的方式;可能存在需要保留 ret 以与 newval 进行比较的情况,但它目前只是一个用户空间 自旋锁.

will compile with newer gcc and binutils. It also uses less registers and is optimal for the way Qt is currently using it; there maybe cases where ret needs to be preserved to compare to newval but it is just a user space spin lock currently.

方括号[x] 是一个内存操作数寄存器,必须不同于有效swp 的其他两个参数.我相信第一种形式用于阻止 %0%3 相同.第二种形式通过使 %0%1 相同来避免这种情况,因此 %2 必须不同.

The bracket [x] is a memory operand register and must be different than the other two parameters for a valid swp. I believe the first form was used to stop %0 from being the same as %3. The 2nd form avoids this by making %0 and %1 the same, so %2 must be different.

这篇关于从源代码为 ARM 交叉编译 Qt 4.7 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆