如何添加相对于当前文件的头文件路径? [英] How to add header files path relative to the current file?
问题描述
我在以下目录中有文件mx_minimum_power.cpp
I have the file mx_minimum_power.cpp
in the following directory
D:\thesis library.Data\ALOS-PALSAR 12x2\San Francisco L 12x2
和我要包含在以下目录中的cpp文件中的14个头文件:
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
,因此相对于我的.cpp
文件,这些.h
文件的相对路径为\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;
}
但是当我在matlab中运行以下命令以构建.mexw64
文件时:
but when I run the following command in matlab in order to build the .mexw64
file:
mex -g mx_minimum_power.cpp
我得到了错误:
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
推荐答案
#include "Eigen/Eigenvalues/first.of.14.h"
...
然后让编译器知道查找.".作为include的基本路径,假设您从源目录运行编译器.在gcc/g ++中,使用"-I".我在MSDN上找不到等效项,但是有一个.我几年前用过.
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.
这从字面上回答了您的问题,但是我会告诉编译器查找"Eigen \ Eigenvalues",然后仅使用上面的14个名称,而不使用两个级别的目录.
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.
这篇关于如何添加相对于当前文件的头文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!