4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Eigenライブラリの使い方

Last updated at Posted at 2018-02-12

Eigenライブラリの使い方

EigenライブラリはC++のテンプレートを使用して作られているヘッダファイルのみで構成される線形代数ライブラリです。数値計算の速度に定評があります。
使い方は至って簡単で、ヘッダファイルをインクルードして一緒にコンパイルしてあげるだけです。

ダウンロード

Eigenの公式サイトから最新版をダウンロードし、適当なディレクトリに置きます。ここでは$HOME/includeとします。

$ cd ~/Downloads
$ wget http://bitbucket.org/eigen/eigen/get/3.3.4.tar.gz   # ダウンロード
$ tar -zxvf 3.3.4.tar.gz                                   # 解凍
$ mv <解凍されてできたディレクトリ名> eigen-3.3.4               # ディレクトリ名を変更
$ mv eigen-3.3.4 ~/include                                 # ~/includeへディレクトリを移動

お好みでシンボリックリンクを作成しておきます。

$ cd ~/include                                             # ~/includeディレクトリへ移動
$ ln -s $HOME/include/eigen-3.3.4 $HOME/include/eigen      # eigen-3.3.4へのシンボリックリンクをeigenという名前で作成

コンパイル方法

例えばtest.cppがEigenライブラリをインクルードして使っているとします。

test.cpp
# include "Eigen/Core"

int main() {
    ... // 処理
}

コンパイル時にEigenライブラリへのインクルードパスを指定してあげましょう。

$ g++ test test.cpp -isystem $HOME/include/eigen

-Iオプションを使ってインクルードディレクトリを指定してもコンパイルできるのですが、警告メッセージが出てきてしまいます。
gccのオプション説明では

You can use -I to override a system header file, substituting your own version, since these directories are searched before the standard system header file directories. However, you should not use this option to add directories that contain vendor-supplied system header files; use -isystem for that.

The -isystem and -idirafter options also mark the directory as a system directory, so that it gets the same special treatment that is applied to the standard system directories.

となっていますので、外部ライブラリを利用する際は不要な警告を出さないよう-isystemでインクルードする方がいいでしょう。

使い方

公式サイトのレファレンスを読めば基本的な使い方は簡単に把握できます。
使い方を思い出せないというときは、クイックレファレンスを参照するのが手っ取り早いです。

コンパイル時にエラーが出て困った時はググりましょう。
ROS.orgのeigen/Troubleshootingはエラー解決に役立ちます。

4
5
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
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?