Skip to content

Instantly share code, notes, and snippets.

@kazz12211
Last active August 30, 2017 06:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazz12211/a6b874de03a65a594e9edb1a52aa6184 to your computer and use it in GitHub Desktop.
Save kazz12211/a6b874de03a65a594e9edb1a52aa6184 to your computer and use it in GitHub Desktop.
EclipseでクロスコンパイルしてリモートのRaspberry Piで動かす

このGistは ブログからの転載です。

概要

Raspberry Piで動くプログラムをC言語などで開発する際に、Raspberry Pi上でソース作成、コンパイル、リンクを行っても良いのですが、使い慣れたIDEを使いたいことがあります。ここではEclipse CDTでRaspberry Pi用のプログラムをクロスコンパイルして、sshを使ってネットワーク接続したRaspberry Piにプログラムをインストールする方法を紹介します。Eclipse CDTがすでにインストールされていることを前提とします。(Ubuntu 16.04LTSでEclipse CDT 4.6.0 を使いました)

1. Raspberry Piツールのインストール

Raspberry Piのgitリポジトリからツールをクローンします。ここにはビルドツールが入っています。

これを例えば $HOME/RaspberryPi にgit cloneコマンドでクローンします。

$ mkdir $HOME/RaspberryPi
$ cd $HOME/RaspberryPi
$ git clone https://github.com/raspberrypi/tools.git

コンパイラやリンカは

$HOME/RaspberryPi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin

にあります。

2. Cプロジェクトの作成

Eclipse CDT上で新規Cプロジェクトを作ります。ウィザードの画面は以下の通り。

大事なところ。

クロスコンパイラのprefixは arm-linux-gnueabihf- です。コンパイラーのパスは$HOME/RaspberryPi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin です。

3. プログラムの作成

プロジェクトにソースフォルダーを作成。

ソースフォルダーのCのソースファイルを作成。

4. プログラムのビルド

“Hello Raspberry Pi!”をstdoutに出力する簡単なプログラム。これをReleaseターゲットでビルドします。

5. 実行の設定と実行

「Run」メニューの「Run Configurations…」を選択。下のスクリーンショットのように設定。

C/C++ ApplicationにはReleaseビルドしたもの、Build ConfigurationはRelease、Remote Absolute File Path for C/C++ Applicationには /home/pi/rpi/HelloRpi(/home/pi/rpiディレクトリは事前にRaspberry Piに作成しておく)、Commands to execute before applicationにはプログラムへの実行権の付与を行うコマンドを設定します。Connectionを設定するまで「Run」を押さない。

ConnectionはSSH接続情報を設定します。上の画面で「New」ボタンを押して、こんな感じに設定。Connection nameはお好みで、HostはRaspberry Piのホスト名かIPアドレス、UserとPasswordは上の画面で設定したRemote Absolute File Path for C/C++ Applicationを書き込みできるユーザー名とパスワードです。

ここで「Run」をクリックすると、リモートのRaspberry Piにプログラムを転送して実行します。

6. 実行結果

下のスクリーンショットはRaspberry Piのターミナルでプログラムを実行した様子です。

デバッグをしたい場合は、5の「実行の設定」部分をデバッグの設定(「Run」メニューの「Debug Configurations…」を選択して設定する)にして、デバッグを実行すればいいです。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment