樹莓派2 raspyberry Pi2 交叉編譯app

來源:互聯網
上載者:User

標籤:

Pi 使用的是ARMV7架構的BCM2836, 下載交叉編譯器 arm-linux-gnueabihf-gcc 即可.

本地環境: Ubuntu14 + x86_64

1. 下載編譯器地址:

1). linaro開源組織有相關的交叉工具鏈下載,點擊進入網頁選擇下載即可,地址:https://launchpad.net/linaro-toolchain-binaries/+download

2). 上述網址網速較慢, 總是下載失敗. 找了國內的網址 http://pan.baidu.com/s/1pJ2rdkZ

 

2. 下載完後, 解壓, 並將 gcc-linaro-arm-linux-gnueabihf-4.9-2014.07_linux/bin 目錄設定到系統內容變數中.

gcc-linaro-arm-linux-gnueabihf-4.9-2014.07_linux/bin$ file arm-linux-gnueabihf-gcc-4.9.1
arm-linux-gnueabihf-gcc-4.9.1: ELF 32-bit LSB  executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped

這裡下載的交叉編譯器的是32位的, 確保你的系統支援32位程式的運行.

3. 準備測試代碼 main.c:

#include <stdio.h>
int main()
{
    printf("hellow world!\n");
}

4. 編譯

arm-linux-gnueabihf-gcc main.c -v

詳細交叉編譯選項為:COLLECT_GCC_OPTIONS=‘-v‘ ‘-march=armv7-a‘ ‘-mtune=cortex-a9‘ ‘-mfloat-abi=hard‘ ‘-mfpu=vfpv3-d16‘ ‘-mthumb‘ ‘-mtls-dialect=gnu‘

編譯結果:

file a.out
a.out: ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.1.1, BuildID[sha1]=3103ff5892a051b7e185e8ae88bf6cb997af7781, not stripped

5. 執行

上傳到 pi 上, 執行結果如下:

[email protected] ~ $ ./a.out
hellow world!
[email protected] ~ $

 

樹莓派2 raspyberry Pi2 交叉編譯app

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.