How can I include a file using Eigen's plugin include?

35 Views Asked by At

I am trying to extend Eigen's matrix classes to work with my own library's using their #define. Eigen is located in /usr/local/include. My project is in a separate folder. I followed the guide specified in their documentation.

Here is where I defined the relative paths for my extensions in a file called SparseMatrix.

#define EIGEN_MATRIXBASE_PLUGIN "src/Eigen_Extension/Matrix_Extension.hpp"
#define EIGEN_SPARSEMATRIX_PLUGIN "src/Eigen_Extension/Sparse_Matrix_Extension.hpp"

#include <Eigen/Core>
#include <Eigen/Sparse>

When I try to compile with g++ test.cpp , I get the error

SparseMatrix:59:33: fatal error: src/Eigen_Extension/Matrix_Extension.hpp: No such file or directory
   59 | #define EIGEN_MATRIXBASE_PLUGIN "src/Eigen_Extension/Matrix_Extension.hpp"
      |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated. 

Despite the error showing my file, I know gcc is trying to include src/Eigen_Extension/Matrix_Extension.hpp in Eigen's .h file. This does compile if I use an absolute path.

My question boils down to: (preferably) without build systems or arguments. how can I make this work with a relative path?

I tried creating a convoluted define structure using _FILE_.

Matrix_Extension.hpp:

#include "../../SparseMatrix"

#ifdef EIGEN_MATRIXBASE_PLUGIN
// source code 
#else
#EIGEN_MATRIXBASE_PLUGIN __FILE__ //to get absolute path of extension file
#endif

SparseMatrix:

#include src/Eigen_Extension/Matrix_Extension.hpp

#include <Eigen/Core>

Unfortunately, this ran into issues with the my code not having Eigen included despite the define guards.

0

There are 0 best solutions below