Ubuntu で ARM プログラムをコンパイルする

Ubuntu で ARM プログラムをコンパイルする

序文

MacBook はすべて arm アーキテクチャの m1 チップを直接使用しており、arm はますます強力になっています。実際、直接的なメリットではありませんが、組み込み Linux 開発者にもメリットをもたらす可能性があります。
Ubuntu のソースはすでに複数のアーキテクチャをサポートしており、平たく言えば、すべての armhf ライブラリ ファイルを x86 コンピュータにインストールできます。x86 プログラムを arm バージョンにコンパイルしたい場合は、gcc を変更するだけでarm-linux-gnueabihf-gcc実現できます。

ステップ

sudo dpkg --add-architecture armhf

ソフトウェア ソースを変更し、/etc/apt/sources.list
各行の前に元の行を追加してdeb [arch=amd64,i386]
から、対応する armhf アーキテクチャを各行の下に追加します。

deb [arch=armhf] http://ports.ubuntu.com/ .....

最終的な修正例:

# deb cdrom:[Ubuntu 18.04.3 LTS _Bionic Beaver_ - Release amd64 (20190805)]/ bionic main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb [arch=amd64,i386] http://cn.archive.ubuntu.com/ubuntu/ bionic main restricted
deb [arch=armhf] http://ports.ubuntu.com/ bionic main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu/ bionic main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb [arch=amd64,i386] http://cn.archive.ubuntu.com/ubuntu/ bionic-updates main restricted
deb [arch=armhf] http://ports.ubuntu.com/ bionic-updates main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu/ bionic-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb [arch=amd64,i386] http://cn.archive.ubuntu.com/ubuntu/ bionic universe
deb [arch=armhf] http://ports.ubuntu.com/ bionic universe
# deb-src http://cn.archive.ubuntu.com/ubuntu/ bionic universe
deb [arch=amd64,i386] http://cn.archive.ubuntu.com/ubuntu/ bionic-updates universe
deb [arch=armhf] http://ports.ubuntu.com/ bionic-updates universe

# deb-src http://cn.archive.ubuntu.com/ubuntu/ bionic-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb [arch=amd64,i386] http://cn.archive.ubuntu.com/ubuntu/ bionic multiverse
deb [arch=armhf] http://ports.ubuntu.com/ bionic multiverse

# deb-src http://cn.archive.ubuntu.com/ubuntu/ bionic multiverse
deb [arch=amd64,i386] http://cn.archive.ubuntu.com/ubuntu/ bionic-updates multiverse
deb [arch=armhf] http://ports.ubuntu.com/ bionic-updates multiverse

# deb-src http://cn.archive.ubuntu.com/ubuntu/ bionic-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb [arch=amd64,i386] http://cn.archive.ubuntu.com/ubuntu/ bionic-backports main restricted universe multiverse
deb [arch=armhf] http://ports.ubuntu.com/ bionic-backports main restricted universe multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ bionic-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu bionic partner
# deb-src http://archive.canonical.com/ubuntu bionic partner

deb [arch=amd64,i386] http://security.ubuntu.com/ubuntu bionic-security main restricted
deb [arch=armhf] http://ports.ubuntu.com/ bionic-security main restricted
# deb-src http://security.ubuntu.com/ubuntu bionic-security main restricted
deb [arch=amd64,i386] http://security.ubuntu.com/ubuntu bionic-security universe
deb [arch=armhf] http://ports.ubuntu.com/ bionic-security universe
# deb-src http://security.ubuntu.com/ubuntu bionic-security universe
deb [arch=amd64,i386] http://security.ubuntu.com/ubuntu bionic-security multiverse
deb [arch=armhf] http://ports.ubuntu.com/ bionic-security multiverse
# deb-src http://security.ubuntu.com/ubuntu bionic-security multiverse
deb https://typora.io/linux ./
# deb-src https://typora.io/linux ./

updateその後、ライブラリをインストールできます。

sudo apt update
sudo apt install crossbuild-essential-armhf libjson-c-dev:armhf libcurl4-openssl-dev:armhf libuv4-dev:armhf libwebsockets8:armhf libwebsockets-dev:armhf

その後、Eclipse は gcc を arm-linux-gnueabihf-gcc に変更するだけで済み、パスを指定しなくてもコンパイルとリンクが成功します。

参考:https://askubuntu.com/a/568468/220641

おすすめ

転載: blog.csdn.net/kangear/article/details/117877023