Eigen

http://eigen.tuxfamily.org/index.php?title=Main_Page

Eigen is a C++ template library for linear algebra: matrices, vectors, numerical solvers, and related algorithms.

wget http://bitbucket.org/eigen/eigen/get/3.3.7.tar.bz2

tar -jxvf 3.3.7.tar.bz2

How to "install" Eigen?

In order to use Eigen, you just need to download and extract Eigen's source code (see the wiki for download instructions). In fact, the header files in the Eigen subdirectory are the only files required to compile programs using Eigen. The header files are the same for all platforms. It is not necessary to use CMake or install anything.

A simple first program

Here is a rather simple program to get you started.

#include <iostream>
#include <Eigen/Dense>
int main()
{
MatrixXd m(2,2);
m(0,0) = 3;
m(1,0) = 2.5;
m(0,1) = -1;
m(1,1) = m(1,0) + m(0,1);
std::cout << m << std::endl;
}

We will explain the program after telling you how to compile it.

Compiling and running your first program

There is no library to link to. The only thing that you need to keep in mind when compiling the above program is that the compiler must be able to find the Eigen header files. The directory in which you placed Eigen's source code must be in the include path. With GCC you use the -I option to achieve this, so you can compile the program with a command like this:

g++ -I /path/to/eigen/ my_program.cpp -o my_program

On Linux or Mac OS X, another option is to symlink or copy the Eigen folder into /usr/local/include/. This way, you can compile the program with:

g++ my_program.cpp -o my_program

When you run the program, it produces the following output:

3 -1
2.5 1.5



原文地址:https://www.cnblogs.com/emanlee/p/13583642.html