ios编译libfreetype,并适应armv7,armv7s,arm64

本文详细记录了解决iOS项目中使用旧版库导致真机编译失败的过程,通过更新依赖库、调整编译参数等步骤,最终成功解决了在iOS真机上的编译问题。对于遇到类似问题的开发者,提供了一个从发现问题到解决问题的完整路径。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在github里看到人人网发布的一个CCHtmlLabel的RichText控件,可以显示复杂的html结构的富文本,配置好之后发现在模拟器上面能顺利跑起来,但在真机上却编译失败。

看error log的意思是指没有armv7s的slice,再看了一下CCHtmlLabel所用的libfreetype库,是2011年编译的,有点旧,当时iphone4s才刚出呢,当然没有armv7s了。

于是到SourceForge下载了freetype的源代码,编译成lib后再替换原来的libfreetype.a,再次用Xcode编译整个游戏项目,发现还是有个linker的错误:undefined reference to `BZ2_bzDecompressInit'

这个简单,在xcode里添加对libbz2.1.0.dylib的引用即可。

有需要的请到这里下载:http://download.youkuaiyun.com/detail/visualcatsharp/7076545


下面再记录一下编译的过程

mkdir /var/tmp/build-armv7


./configure CFLAGS="-arch i386"
make
cp objs/.libs/libfreetype.a libfreetype-i386.a


./configure CFLAGS="-arch x86_64";make clean;make
cp objs/.libs/libfreetype.a libfreetype-x86_64.a


make clean
./configure --prefix=/var/tmp/build-armv7 --host=arm-apple-darwin --enable-static=yes --enable-shared=no CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc CFLAGS="-arch armv7 -pipe -std=c99 -Wno-extended-offsetof -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=4.2 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk" AR=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar LDFLAGS="-arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk -miphoneos-version-min=4.2"
make
cp objs/.libs/libfreetype.a libfreetype-arm7.a


make clean
./configure --prefix=/var/tmp/build-armv7 --host=arm-apple-darwin --enable-static=yes --enable-shared=no CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc CFLAGS="-arch armv7s -pipe -std=c99 -Wno-extended-offsetof -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=4.2 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk" AR=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar LDFLAGS="-arch armv7s -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk -miphoneos-version-min=4.2"
make
cp objs/.libs/libfreetype.a libfreetype-arm7s.a


make clean
./configure --prefix=/var/tmp/build-armv7 --host=arm-apple-darwin --enable-static=yes --enable-shared=no CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc CFLAGS="-arch arm64 -pipe -std=c99 -Wno-extended-offsetof -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=6.0 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk" AR=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar LDFLAGS="-arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk -miphoneos-version-min=6.0"
make clean; make
cp objs/.libs/libfreetype.a libfreetype-arm64.a


lipo -create -output libfreetype.a libfreetype-i386.a libfreetype-x86_64.a libfreetype-arm7.a libfreetype-arm7s.a libfreetype-arm64.a
lipo -info libfreetype.a

<think>我们正在处理用户关于在ARM64架构的Linux上编译Qt Creator 4.3.1的问题。根据用户提供的引用,我们注意到引用[1]提到了Qt Creator的编译器套件配置问题,引用[2]提供了一个Makefile示例,用于ARM64架构的模块编译,这为我们提供了交叉编译的参考。 编译Qt Creator通常需要从源代码构建,且需要满足其依赖项。由于目标平台是ARM64,我们假设用户已经在ARM64的Linux系统上(例如使用树莓派或其它ARM64开发板),或者用户正在使用交叉编译工具链从其他架构的主机为ARM64目标编译。 步骤概述: 1. 准备编译环境:安装必要的构建工具和依赖库。 2. 获取Qt Creator 4.3.1的源代码。 3. 配置编译选项,指定Qt库的位置(因为Qt Creator依赖于Qt库)。 4. 编译和安装。 详细步骤: 1. 准备环境: - 确保系统已安装必要的开发工具和库。在基于Debian的系统(如Ubuntu)上,可以使用以下命令: ```bash sudo apt update sudo apt install build-essential cmake git libgl1-mesa-dev libssl-dev ``` - 由于Qt Creator是用C++编写的,且使用Qt库,因此需要先安装Qt库。注意:Qt Creator的版本4.3.1需要特定版本的Qt库(通常需要Qt 5.9或更高版本)。用户可以选择安装预编译的Qt库,或者从源代码编译Qt库。这里假设用户已经在系统上安装了适用于ARM64的Qt库(例如通过包管理器或自行编译)。 2. 获取源代码: - 从Qt官方仓库获取Qt Creator的源代码。注意,我们需要特定版本4.3.1。可以通过git检出该标签: ```bash git clone git://code.qt.io/qt-creator/qt-creator.git cd qt-creator git checkout v4.3.1 ``` 3. 配置: - 创建一个构建目录,运行qmake(或使用cmake,具体取决于Qt Creator的版本。注意:Qt Creator从4.0开始使用qmake构建,但后来版本转用cmake。4.3.1版本仍然使用qmake)。因此,我们需要使用qmake来生成Makefile。 ```bash mkdir build cd build qmake -r ../qt-creator/qtcreator.pro ``` 如果系统上安装了多个Qt版本,可能需要指定qmake的完整路径(例如:`/path/to/qt/bin/qmake`)。另外,如果Qt库是交叉编译的,那么需要确保qmake是针对ARM64的。 4. 编译: - 运行make命令进行编译。由于编译过程可能较长,可以使用多线程编译: ```bash make -j$(nproc) ``` 5. 安装: - 编译完成后,安装到指定目录(默认为/usr/local): ```bash sudo make install ``` 注意:如果用户是在ARM64设备上本地编译,那么上述步骤即可。但如果是交叉编译(即在x86_64主机上编译ARM64目标),则需要配置交叉编译工具链。这通常涉及到指定交叉编译工具链的路径和架构。但是,用户的问题中没有明确说明是本地编译还是交叉编译,我们假设是本地编译(因为用户说“在ARM64架构的Linux电脑上”)。 另外,引用[1]中提到的编译器套件配置问题,在编译Qt Creator之后,运行Qt Creator时可能需要配置编译器套件(如gcc、g++等)和Qt版本。这可以在Qt Creator的“选项”菜单中进行配置。 引用[2]提供了一个Makefile示例,其中设置了环境变量`ARCH=arm64`和`CROSS_COMPILE=aarch64-linux-gnu-`,这提示我们在交叉编译时需要设置这些环境变量。但是,由于用户是在ARM64的Linux电脑上编译,所以不需要交叉编译,因此不需要设置这些变量。 然而,如果用户实际上是想在x86主机上交叉编译Qt Creator以在ARM64设备上运行,那么步骤会有所不同。我们需要配置交叉编译工具链,确保Qt库也是为ARM64交叉编译的。这种情况下,配置步骤可能如下: 1. 安装交叉编译工具链(如gcc-aarch64-linux-gnu)。 2. 交叉编译Qt库(这本身是一个复杂的过程)。 3. 在配置Qt Creator时,使用交叉编译的Qt库中的qmake,设置交叉编译器。 由于用户问题没有明确说明,我们按照本地编译来提供步骤。 最后,生成相关问题: §§相关问题§§ 1. 在ARM64架构上编译Qt Creator时,如何处理依赖库的安装? 2. 如何为Qt Creator配置交叉编译工具链? 3. Qt Creator 4.3.1支持哪些版本的Qt库? 4. 在编译过程中遇到错误如何解决?</think>### 在ARM64架构Linux上编译Qt Creator 4.3.1的步骤 #### 1. **安装依赖项** ```bash sudo apt update sudo apt install -y build-essential cmake git libgl1-mesa-dev \ libssl-dev libxcb-xinerama0-dev libfontconfig1-dev \ libfreetype6-dev libx11-dev libxext-dev libxfixes-dev \ libxi-dev libxrender-dev libxcb1-dev libx11-xcb-dev \ libxcb-glx0-dev libxkbcommon-dev libxkbcommon-x11-dev \ libclang-11-dev llvm-11 libclang-11 ``` #### 2. **获取源代码** ```bash git clone git://code.qt.io/qt-creator/qt-creator.git cd qt-creator git checkout v4.3.1 ``` #### 3. **配置ARM64编译环境** 创建编译目录配置: ```bash mkdir build && cd build cmake .. \ -DCMAKE_PREFIX_PATH=/usr/lib/aarch64-linux-gnu \ -DCMAKE_INSTALL_PREFIX=/opt/qtcreator \ -DCMAKE_BUILD_TYPE=Release \ -DLLVM_INSTALL_DIR=/usr/lib/llvm-11 ``` #### 4. **编译安装** ```bash make -j$(nproc) sudo make install ``` #### 5. **配置环境变量** ```bash echo 'export PATH=/opt/qtcreator/bin:$PATH' >> ~/.bashrc source ~/.bashrc ``` #### 6. **验证安装** ```bash qtcreator --version # 应输出: Qt Creator 4.3.1 ``` ### 关键配置说明 1. **架构适配**: 通过`CMAKE_PREFIX_PATH`指定ARM64库路径,确保链接正确的库文件[^1] 2. **LLVM依赖**: Qt Creator需要LLVM支持代码分析,需明确指定`LLVM_INSTALL_DIR`路径[^2] 3. **编译器选择**: 系统默认的`g++`编译器会自动适配ARM64架构,无需额外配置交叉编译工具链 ### 常见问题解决 1. **缺少OpenGL库**: ```bash sudo apt install libglu1-mesa-dev ``` 2. **QML模块错误**: 在CMake配置中添加: `-DQT_QMAKE_EXECUTABLE=/path/to/qmake` 3. **插件加载失败**: 清除配置后重启: ```bash rm ~/.config/QtProject/qtcreator.ini ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值