views:

83

answers:

3

Hi Guys, I'm making use of Eigen library which promises vectorization of matrix operations. I don't know how to use the files given in Eigen and write a makefile. The source files which make use of Eigen include files as listed below, these are not even header files (They are just some text files)-

<Eigen/Core>
<Eigen/Dense>
<Eigen/Eigen>

and so on. On Eigen's webpage, it's mentioned that, in order to use its functions I don't have to build the project, then how can I include these files in my makefile to build my project. My example main.c file looks like this. Can anyone show me how to write a makefile makefile for this file -

#include <Eigen/Core>

// import most common Eigen types 
USING_PART_OF_NAMESPACE_EIGEN

int main(int, char *[])
{
  Matrix3f m3;
  m3 << 1, 2, 3, 4, 5, 6, 7, 8, 9;
  Matrix4f m4 = Matrix4f::Identity();
  Vector4i v4(1, 2, 3, 4);

  std::cout << "m3\n" << m3 << "\nm4:\n"
    << m4 << "\nv4:\n" << v4 << std::endl;
}

Help!

A: 

They have this in their documentation .

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

There is no library to link to. 

It seems you just have to add the template(header) file path to your include directories inside your Makefile.

DumbCoder
+3  A: 

According to Eigen's website, this is a header-only library.

This means there is nothing to compile or link it to. Instead, as long as you have the header files in a standard location (/usr/local/include on *nix/Mac), then all you have to do is add that location to your preprocessor build step.

Assuming that you are running *nix/Mac, and assuming that you have everything installed to the default locations (e.g. #include <Eigen/Core> references the file /usr/local/include/Eigen/Core), then a SUPER simple makefile would look like this:

main: main.cpp
    g++ -I /usr/local/include main.cpp -o main

Which says, in English:

  • main depends on main.cpp
  • to make main, use g++ to
    • compile main.cpp,
    • output file main,
    • looking in the directory /usr/local/include for any headers it doesn't know about

NOTE: there is a TAB in front of the g++ line, NOT four spaces.

Hope that helps.

Austin Hyde
A: 

Those are in fact header files. Eigen is a template library, and following common template practice includes definition and declaration all in header files, as apposed to non-template practice of keeping definitions and declarations in separate files. When decelerations and definitions are kept separate, you must build the source files containing definitions into library object files to be linked into your program.

This is already ostensibly done for you merely by the act of including the Eigen header files in the first place.

As long as you have installed the Eigen header files into your system include path, they will be compiled into your program without any customization on your part. If you have not installed them into your include path, simply provide the full path to g++ like so...

g++ -I /path/to/eigen2/ source_file -o output_file
itsmyown