x86架构下ubuntu交叉编译器(arm-linux-gnueabihf-)直接下载使用arm架构的库

 🗣️前言

这里以libcurl库为例,本文提供的方法能直接安装,不用自己编译。但是会和x86架构的库冲突,如果安装了这个,再开发x86架构的软件就需要重新安装对应架构的库。这里建议是将一个环境作为一种平台的开发,不要混用。

🔧安装步骤

🛹卸载x86版本的libcurl

# 卸载x86版本的libcurl
sudo apt remove --purge libcurl4-openssl-dev
sudo apt-get autoremove

🧨配置arm源

以清华源为例,参考网页

x86架构:https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/

arm等架构:https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu-ports/

完整配置文件如下,记得一定要加入Architectures: amd64或Architectures: Architectures: armhf

# 下面是x86架构的软件源
Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
Suites: noble noble-updates noble-backports
Components: main restricted universe multiverse
Architectures: amd64    # 重要,必须要加
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main restricted universe multiverse
Architectures: amd64    # 重要,必须要加
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

# 下面是Ubuntu Ports软件仓库,也就是arm等架构的软件源
Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports
Suites: noble noble-updates noble-backports
Components: main restricted universe multiverse
Architectures: armhf    # 重要,必须要加
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
Types: deb
URIs: http://ports.ubuntu.com/ubuntu-ports/
Suites: noble-security
Components: main restricted universe multiverse
Architectures: armhf    # 重要,必须要加
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

🛫安装arm版本lincurl

sudo dpkg --add-architecture armhf    # 为了让系统知道可以使用arm架构的库
sudo apt update
sudo apt install libcurl4-gnutls-dev:armhf

 安装完成之后,会在\usr\include\arm-linux-gnueabihf生成相应的头文件

🌴vscode配置

我使用的是vscode配置,然后源码解析工具是clangd,为了能使其找到相应的库,在项目目录下创建一个.clangd文件并写入如下内容

CompileFlags:
  Compiler: /usr/bin/arm-linux-gnueabihf-gcc    # 配置编译器后会自动找相应的头文件

编译时记得加上-lcurl选项,如

arm-linux-gnueabihf-gcc xxx.c -o xxx -lcurl

🔚结语

这就可以了,一定要记住x86和arm是冲突的

🗂️参考

感谢ChatGPT和Gemini的帮助

posted @ 2026-01-11 19:50  绿树荫下跑猫猫  阅读(0)  评论(0)    收藏  举报