【问题标题】:How to add header files path relative to the current file?如何添加相对于当前文件的头文件路径?
【发布时间】:2017-05-16 18:44:14
【问题描述】:

我在以下目录中有文件mx_minimum_power.cpp

D:\thesis library.Data\ALOS-PALSAR 12x2\San Francisco L 12x2  

还有14个头文件,我想包含在以下目录中的cpp文件中:

D:\thesis library.Data\ALOS-PALSAR 12x2\San Francisco L 12x2\Eigen\Eigenvalues  

所以这些.h 文件相对于我的.cpp 文件的相对路径是\Eigen\Eigenvalues
我应该如何包含所有这些头文件的相对路径。
到目前为止我已经完成了:

#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 文件时:

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\header.h" 或考虑这个问题的技术 - stackoverflow.com/questions/3061582/…
  • 我可能是少数,但我认为#include 指令中的路径是个坏主意。如果我有时间,我会尝试从那些试图在遗留代码中解决这些问题的人那里找到一些问题。
  • #include "\Eigen\Eigenvalues" 表示在名为Eigen 的文件夹中查找文件Eigenvalues,该文件夹位于代码所在驱动器的根目录中。在这种情况下,它正在查找文件@987654337 @

标签: c++ matlab visual-studio-2013 eigen mex


【解决方案1】:
#include "Eigen/Eigenvalues/first.of.14.h"
...

然后让编译器知道要查找“。”作为包含的基本路径,假设您从源目录运行编译器。在 gcc/g++ 中使用“-I.”。我在 MSDN 上找不到等价物,但有一个。我几年前用过。

这确实回答了您的问题,但我会告诉编译器查看“Eigen\Eigenvalues”,然后只使用上面的 14 个名称,而不使用两级目录。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-22
    • 1970-01-01
    • 1970-01-01
    • 2017-09-30
    相关资源
    最近更新 更多