从 ARM 源代码交叉编译 Qt 4.7 的问题 [英] Problems cross compiling Qt 4.7 from source for ARM
问题描述
我正在尝试从源代码交叉编译 Qt 4.7.1,这里有一些关于我的设置的注意事项:
I'm trying to cross-compile Qt 4.7.1 from source, here are some notes on my setup:
- 我的预期输出是运行 Qt 应用程序所需的共享对象库.
- 我的目标平台是采用 ARM Cortex-A8 架构的 TI AM335x 处理器.
- 我的开发平台是 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 -DQTNAMESPACE-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]"
make[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 支持 thumb、thumb2 和 ARM.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.
详细参见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 有另一个问题这解决了他的问题;但我认为这是不同的.
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 获取定义列表- </dev/null
,验证__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
.出于某种原因,我使用其他优化和更新的 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 代码相当混乱,更新的 gcc
或 binutils 即使在这是要使用的正确文件.
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");
将使用更新的 gcc
和 binutils 进行编译.它还使用较少的寄存器,并且是 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屋!