问题
I have the file mx_minimum_power.cpp
in the following directory
D:\thesis library.Data\ALOS-PALSAR 12x2\San Francisco L 12x2
and 14 header files that I want to include to the cpp file in the following directory:
D:\thesis library.Data\ALOS-PALSAR 12x2\San Francisco L 12x2\Eigen\Eigenvalues
so the relative path to these .h
files with respect to my .cpp
file is \Eigen\Eigenvalues
How should I include all those header files relative path.
I've done so far:
#include <math.h>
#include <complex>
#include <iostream>
#include "mex.h"
#include "matrix.h"
#include "\Eigen\Eigenvalues"
using std::complex;
using std::cout;
using std::endl;
using namespace Eigen;
/* The gateway function */
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
double *arraysizePtr = NULL;
arraysizePtr = mxGetPr(prhs[9]);
const int arraysize = (int)*arraysizePtr;
const int matrixDimention = 3;
}
but when I run the following command in matlab in order to build the .mexw64
file:
mex -g mx_minimum_power.cpp
I get the error:
Building with 'Microsoft Visual C++ 2013 Professional'.
Error using mex
mx_minimum_power.cpp
D:\thesis library.Data\ALOS-PALSAR 12x2\San Francisco L 12x2\mx_minimum_power.cpp(6) : fatal
error C1083: Cannot open include file: '\Eigen\Eigenvalues': No such file or directory
回答1:
#include "Eigen/Eigenvalues/first.of.14.h"
...
Then let the compiler know to look in "." as a base path for includes, assuming you run the compiler from the source directory. In gcc/g++ one uses "-I.". I couldn't find the equivalent on MSDN, but there is one. I used it years ago.
That literally answers your question, but I would tell the compiler to look in "Eigen\Eigenvalues" and then just use the 14 names as above without the two levels of directories.
来源:https://stackoverflow.com/questions/41430558/how-to-add-header-files-path-relative-to-the-current-file