【Linux开发】【Qt开发】arm-linux-gnueabihf-gdb versus gdb-multiarch

本文介绍了如何解决在Ubuntu 14.04系统上使用Qt进行ARM设备远程调试遇到的问题。通过安装gdb-multiarch替代arm-linux-gnueabihf-gdb,实现了跨平台远程调试功能。

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

主要是说,在Ubuntu14.04 64bit的操作系统上,配置Qt的gdb和gcc的时候,在Qt build&run选项中,debugger中选中arm-linux-gnuabihf-gdb出现了32bit不兼容的情况,于是无法远程调试debug,只能运行。后来在Stack Overflow中找到gdb-multiarch,字面上理解好像是支持多个架构!然后尝试用apt-get install gdb-multiarch,然后居然成功了,在/usr/bin/路径下有了gdb-multiarch,设置过后能够正常识别,然后在Qt中可以实现断点调试了。



arm-linux-gnueabihf-gdb versus gdb-multiarch

I'm trying to perform cross platform remote debugging from my x86 computer to a remote ARM device. (ex: Beagle Bone Black)

I'm using Ubuntu 14.04 and Eclipse CDT.

I installed the package gcc-arm-linux-gnueabihf but the gdb debugger is not in that package. (http://packages.ubuntu.com/precise/gcc-arm-linux-gnueabihf)

Therefore, I'm wondering if I should use the Linaro toolchain (which include arm-linux-gnueabihf-gdb) or if I should install the gdb-multiarch package.

What is the difference between gdb-multiarch and arm-linux-gnueabihf-gdb ? Is it better to use gdb-multiarch ?



I received an answer from the linaro mailing list:

For Ubuntu hosts from 12.04 onwards, gdb-multiarch is used as gdb client for debugging. As name indicates it is a common client to any architecture and not restricted to ARM.

Generally, all gdb clients are architecture independent because architecture specific part is handled in gdbserver itself. So, other than the name arm-linux-gnueabihf-gdb, I am guessing it is same as gdb-multiarch.


I received another answer from the linaro mailing list:

The Linaro gdb release will generally be more up to date than the Ubuntu one. For example our latest release is 7.8, and that is only available in utopic, not trusty so if you plan to use an Ubuntu LTS release it might be better to use the Linaro shipped gdb. Linaro gdb also contains fixes and improvements that aren't in the upstream stable branch. Historically Ubuntu has often picked these changes up too but that may not always be the case.

gdb-multiarch obviously supports a range of other architectures besides ARM, so if that is something that would be useful for you then it might make sense to use that.

转载于:https://www.cnblogs.com/huty/p/8518273.html

<think>根据您提供的`ls`输出,可以看到在`/usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin`目录下确实存在`arm-linux-gnueabihf-gcc`等工具链程序。因此,问题可能出在环境变量加载或者权限上。 ### 解决方案步骤 #### 1. 检查环境变量是否在当前会话生效 虽然您已经将工具链路径添加到`/etc/profile`中,但可能没有重新加载该文件。请执行: ```bash source /etc/profile ``` 然后再次尝试运行命令: ```bash arm-linux-gnueabihf-gcc --version ``` #### 2. 检查工具链的权限 使用`ls -l`检查工具链文件的权限: ```bash ls -l /usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc ``` 如果缺少执行权限(`x`),则使用以下命令添加: ```bash sudo chmod +x /usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-* ``` #### 3. 检查32位库依赖(重要) 在64位系统上运行32位工具链程序需要安装32位兼容库。执行以下命令安装: ```bash sudo apt-get update sudo apt-get install lib32z1 lib32ncurses5 lib32stdc++6 ``` #### 4. 验证工具链是否可运行 使用完整路径运行编译器: ```bash /usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc --version ``` 如果出现类似以下输出,则说明工具链本身正常: ``` arm-linux-gnueabihf-gcc (Linaro GCC 4.9-2017.01) 4.9.4 Copyright (C) 2015 Free Software Foundation, Inc. ... ``` #### 5. 创建符号链接(可选) 如果上述步骤都正常,但使用命令时仍报错,可以尝试在`/usr/local/bin`中创建符号链接: ```bash sudo ln -s /usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc /usr/local/bin/ ``` 然后测试: ```bash arm-linux-gnueabihf-gcc --version ``` ### 自动化检测脚本 以下脚本可以自动检测并修复常见问题: ```bash #!/bin/bash # 定义工具链路径和编译器 TOOLCHAIN_DIR="/usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin" COMPILER_PATH="$TOOLCHAIN_DIR/arm-linux-gnueabihf-gcc" # 检查编译器是否存在 if [ ! -f "$COMPILER_PATH" ]; then echo "错误: 编译器未找到: $COMPILER_PATH" exit 1 fi # 检查权限 if [ ! -x "$COMPILER_PATH" ]; then echo "修复权限: $COMPILER_PATH" sudo chmod +x "$COMPILER_PATH" fi # 检查32位库依赖 echo "检查32位依赖库..." ldd "$COMPILER_PATH" | grep "not found" > /dev/null if [ $? -eq 0 ]; then echo "发现缺失的32位库,正在安装..." sudo apt-get update sudo apt-get install -y lib32z1 lib32ncurses5 lib32stdc++6 fi # 验证编译器 echo "测试编译器..." "$COMPILER_PATH" --version > /dev/null 2>&1 if [ $? -eq 0 ]; then echo "成功: 编译器工作正常。" exit 0 else echo "错误: 编译器无法运行。" echo "尝试手动运行: $COMPILER_PATH --version" exit 1 fi ``` ### 使用说明 1. 将上述脚本保存为`fix_toolchain.sh` 2. 赋予执行权限:`chmod +x fix_toolchain.sh` 3. 运行脚本:`./fix_toolchain.sh` ### 编译示例 成功修复后,编译您的汇编文件: ```bash cd ~/linux/1_leds arm-linux-gnueabihf-gcc -g -c led.s -o led.o ``` §§相关问题§§: 1. 如何为不同的ARM架构(如Cortex-A, Cortex-M)选择正确的工具链? 2. 在Linux中,如何永久添加环境变量到用户配置文件中? 3. 交叉编译时如何处理目标系统的动态链接库? 4. 如何编写一个Makefile来支持交叉编译?</think>根据您列出的工具链目录内容,可以看到交叉编译工具链已正确安装。现在我们将解决之前遇到的权限和命令找不到问题,并提供完整的交叉编译流程。 ### 完整解决方案 #### 1. 修复权限问题(关键步骤) ```bash # 修复工具链权限 sudo chmod -R 755 /usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf # 修复工作目录权限(替换k1为您的用户名) sudo chown -R k1:k1 ~/linux chmod 755 ~/linux/1_leds ``` #### 2. 验证工具链可执行性 ```bash # 直接运行编译器(使用完整路径) /usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc --version # 如果显示版本信息,说明工具链本身正常 # 如果报错,可能是缺少32位库 ``` #### 3. 安装必要的32位兼容库 ```bash sudo apt-get update sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 zlib1g:i386 ``` #### 4. 创建别名简化命令(可选) ```bash # 添加到 ~/.bashrc echo "alias arm-gcc='/usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc'" >> ~/.bashrc source ~/.bashrc # 现在可以使用简化命令 arm-gcc --version ``` ### 完整的交叉编译示例 #### 示例汇编代码 (led.s) ```assembly /* led.s - 简单的ARM汇编LED控制示例 */ .global main main: MOV R0, #1 @ 设置GPIO输出值 BX LR @ 返回 ``` #### 编译步骤 ```bash cd ~/linux/1_leds # 1. 汇编 arm-linux-gnueabihf-gcc -g -c led.s -o led.o # 2. 链接 arm-linux-gnueabihf-gcc -nostdlib -o led led.o # 3. 检查生成的文件 file led # 应该输出: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, not stripped ``` ### 自动化编译脚本 ```bash #!/bin/bash # build_arm.sh - ARM交叉编译脚本 TOOLCHAIN_PATH="/usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin" CC="${TOOLCHAIN_PATH}/arm-linux-gnueabihf-gcc" OUTPUT="led" echo "正在编译ARM程序..." $CC -g -c led.s -o led.o if [ $? -ne 0 ]; then echo "汇编失败!" exit 1 fi $CC -nostdlib -o $OUTPUT led.o if [ $? -ne 0 ]; then echo "链接失败!" exit 1 fi echo "编译成功! 输出文件: $OUTPUT" file $OUTPUT ``` ### 使用说明 1. 将上述脚本保存为 `build_arm.sh` 2. 添加执行权限:`chmod +x build_arm.sh` 3. 运行脚本:`./build_arm.sh` ### 交叉编译工作流程总结 1. **环境准备**:安装工具链,设置PATH 2. **权限修复**:确保工具链和工作目录有正确权限 3. **依赖安装**:安装32位兼容库 4. **编译过程**: - 汇编:`arm-linux-gnueabihf-gcc -c file.s -o file.o` - 链接:`arm-linux-gnueabihf-gcc -o executable file.o` 5. **验证**:使用`file`命令检查输出文件类型
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值