LoginSignup
8
6

More than 5 years have passed since last update.

Raspberry Piのクロスコンパイル環境を整える

Last updated at Posted at 2017-03-05

コンパイラのインストール

$ git clone git@github.com:raspberrypi/tools.git
$ cd tools
$ cp -r arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf /opt
$ export PATH=$PATH:/opt/arm-rpi-4.9.3-linux-gnueabihf/bin >> ~/.bash_profle
$ source ~/.bash_profile

これでarm-linux-gnueabihf-c++が使えるようになる。終わり。これ以降は便利なライブラリをビルドしてみる手順。

mraa のビルド

I/Oを操作するのにmraaがあると便利ではないかと思うのでインストールする。この資料に従って作業していく。今回は共有ライブラリでなく静的ライブラリを生成するようにした。ラズパイにデプロイしたときに、ファイルが無いとか言われると面倒なので。

$ sudo apt-get install swig3.0 python-dev nodejs-dev cmake libjson-c-dev
$ git clone git@github.com:intel-iot-devkit/mraa.git
$ cd mraa
$ mkdir build
$ cd build
$ cmake -DCMAKE_INSTALL_PREFIX:PATH=/home/ubuntu/vanilla/thirdparty/mraa -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_COMPILER=/opt/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc -DCMAKE_CXX_COMPILER=/opt/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-c++ -DBUILDARCH=arm ..
$ make
$ sudo make install

試しにexampleなんかをビルドしてみる。

$ arm-linux-gnueabihf-c++ ./test.cpp -I../thirdparty/mraa/include -L../thirdparty/mraa/lib -lpthread -lmraa -o test

Boostのビルド

C++書いてたらBoostが欲しくなると思うのでビルドする。
VM上で作業している場合は、メモリが足りなくなるので、4Gくらいには増やしておく。

クロスコンパイルの設定用に~/user-config.jamを作成する。

user-config.jam
using gcc : arm
  : arm-linux-gnueabihf-c++
  : <compileflags>--sysroot=/opt/arm-rpi-4.9.3-linux-gnueabihf/arm-linux-gnueabihf/sysroot
  <cxxflags>-I/opt/arm-rpi-4.9.3-linux-gnueabihf/arm-linux-gnueabihf/sysroot/usr/include
  <cxxflags>-I/opt/arm-rpi-4.9.3-linux-gnueabihf/arm-linux-gnueabihf/include/c++/4.9.3
  ;

using python : 2.7
  : /usr/bin/python
  : /opt/arm-rpi-4.9.3-linux-gnueabihf
  /opt/arm-rpi-4.9.3-linux-gnueabihf/arm-linux-gnueabihf/python2.7
  /opt/arm-rpi-4.9.3-linux-gnueabihf/python2.7
  ;

pythonのライブラリがtoolsに含まれていないため、python関係のモジュールのビルドが失敗してしまうので
https://packages.debian.org/jessie/libpython2.7-dev から取ってきて配置する。

$ wget http://http.us.debian.org/debian/pool/main/p/python2.7/libpython2.7-dev_2.7.9-2+deb8u1_armhf.deb
$ dpkg -x libpython2.7-dev_2.7.9-2+deb8u1_armhf.deb libpython2.7-dev_2.7.9-2_armhf_extracted
$ sudo cp -r libpython2.7-dev_2.7.9-2_armhf_extracted/usr/include/arm-linux-gnueabihf/python2.7/ /opt/arm-rpi-4.9.3-linux-gnueabihf/arm-linux-gnueabihf
$ sudo cp -r libpython2.7-dev_2.7.9-2_armhf_extracted/usr/lib/python2.7/config-arm-linux-gnueabihf/ /opt/arm-rpi-4.9.3-linux-gnueabihf/lib/python2.7
$ sudo cp -r libpython2.7-dev_2.7.9-2_armhf_extracted/usr/include/python2.7/ /opt/arm-rpi-4.9.3-linux-gnueabihf

boostをダウンロードしてきて適当なところに展開する。

$ mkdir ./boost
$ wget -O Boost.tar.gz https://sourceforge.net/projects/boost/files/boost/1.63.0/boost_1_63_0.tar.gz/download
$ tar xvzf Boost.tar.gz

適当に/opt/boost以下にビルドしてみる。これもstaticライブラリとしてビルドすることにする。デプロイが(以下略

./b2 install -j2 --prefix=/opt/boost --toolset=gcc link=static

しばらく待つと、

#error "platform not supported"

...

...skipped 9 targets...

とかで一部ビルドできないが、大体できた。もし使えないモジュールあったらごめんなさい。

8
6
0

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
8
6