2013/08/27

32bit Linux上のperlで64bitを扱う

友人たちと起こしているプロジェクトでのこと。
私の環境は ArchLinux 64bitなどですが、メンバーには Ubuntu 32bit使いが居ます。
先日、プロジェクトで使うデータベースドライバを一部置き換えるために、"Mango"というNon-blockingなMongoDBドライバをcpanでインストールしようとしたところ、"Perl with support for quads is required!" とエラーが表示されて、インストールできなかった...という報告を受けました。

MangoのMakefile.PLを見ると、$Config{use64bitint}が定義されていて、かつ、${longsize}が8以上である必要があるようです。
即ち、64bitモードのperlでなければならないという事ですね。たぶん。
しかし...次からは、事前にもっときちんとチェックしないと(...反省)

さて...。perlは、32bit環境のOSでも、64bitとしてシミュレートができます。
http://search.cpan.org/~rjbs/perl-5.18.1/INSTALL#64_bit_support
ついては、perlをビルドする際に、"-Duse64bitint" または "-Duse64bitall" オプションを付けると良いようです。

perlbrewを用いてビルド&インストールする場合は、以下のように行います。
(以下は、Redhat系での例。Ubuntuの場合は、yumの代わりに、apt-getで"build-essential"をインストールすると良いはず。)
$ sudo yum install glibc-devel.i686 libgcc.i686 make gcc
$ curl -L http://install.perlbrew.pl | bash
$ source ~/perl5/perlbrew/etc/bashrc
$ perlbrew install 5.18.1 -Duse64bitint
$ perlbrew switch 5.18.1
$ echo source ~/perl5/perlbrew/etc/bashrc >> ~/.bashrc
$ source ~/.bashrc

perl -v すると、i686-linux-64int という表示が確認できます。
$ perl -v
This is perl 5, version 18, subversion 1 (v5.18.1) built for i686-linux-64int

Copyright 1987-2013, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

これでとりあえず問題なく、Mangoもインストールすることができるはずです。

2013/08/20

Arduino+Bluetoothシリアル通信によるワイヤレスなLED制御

Arduino Leonardoに Bluetoothモジュールを接続して、
シリアル通信で、ワイヤレスなLED制御 (Lチカ) をしてみました。
Android端末とペアリングして制御することもできます。
とりあえずはそれだけですが、かなり簡単です。(ありがたいことにドキュメントも沢山あります。)



今回用いたモノ:

  • "Arduino Leonardo"
  • "Bluetoothモジュール RBT-001"
    技適取得済みのBluetooth2.0(SPP/GAP/SDAP)モジュールです。
  • "RBT-001用シリアルレベルコンバータ Rev.3"
    Arduinoは3.3/5V、RBT-001は3V駆動なので変換が必要です。
    今回は手軽なこの変換基板を用いました。
    これと同様の基板はRBT-001を取り扱っている各社から出ています。
  • "高輝度5mm青色LED OSUB5111A"
    手持ちのLEDです。
  • "カーボン抵抗 1kΩ"

以下、手順を簡単に説明しておきます。