VOOZH about

URL: https://qiita.com/kazz12211/items/23cd36b5aaf7322417c0

⇱ EclipseでクロスコンパイルしてリモートのRaspberry Piで動かす #RaspberryPi - Qiita


👁 Image
2

Go to list of users who liked

3

Share on X(Twitter)

Share on Facebook

Add to Hatena Bookmark

More than 5 years have passed since last update.

@kazz12211(Kazuo Tsubaki)

EclipseでクロスコンパイルしてリモートのRaspberry Piで動かす

2
Posted at

ブログからの転載です。

概要

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プロジェクトを作ります。ウィザードの画面は以下の通り。

👁 Image

👁 Image

大事なところ。

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

👁 Image

3. プログラムの作成

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

👁 Image

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

👁 Image

4. プログラムのビルド

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

👁 Image

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」を押さない。

👁 Image

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

👁 Image

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

6. 実行結果

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

👁 Image

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

2

Go to list of users who liked

3
0

Go to list of comments

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2

Go to list of users who liked

3