首页 > 解决方案 > 使用 MEX 编译 C++ 文件

问题描述

我需要编译 cpp 代码,但我收到以下消息:

Building with 'Xcode Clang++'.
Error using mex
~/code_sparse_group_lasso/linNest.cpp:395:2:
error: no matching function for call to 'linNest'
        linNest(X, y, index, nrow, ncol, numGroup, rangeGroupInd, groupLen,
        lambda1, lambda2, beta, innerIter, outerIter, thresh, outerThresh,
        eta, gamma, betaIsZero, step, reset);
        ^~~~~~~
~/code_sparse_group_lasso/linNest.cpp:276:6:
note: candidate function not viable: no known conversion from 'int' to 'int
*' for 3rd argument; take the address of the argument with &
void linNest(double *X, double* y, int *index, int *nrow, int *ncol, int
*numGroup, int *rangeGroupInd, int *groupLen, double *lambda1, double
*lambda2, double *beta, int *innerIter, int *outerIter, double *thresh,
double *outerThresh, double *eta, double *gamma, int *betaIsZero, double
*step, int *reset)
     ^
1 error generated.

我认为错误来自未正确指定变量。有人可以帮忙吗?

标签: c++matlabmex

解决方案


错误消息告诉您“候选函数不可行:第三个参数没有从 'int' 到 'int*' 的已知转换;使用 & 获取参数的地址”。您绝对应该尝试这样做,更改当前行:

linNest(X, y, index, nrow, ncol, numGroup, rangeGroupInd, groupLen, lambda1, lambda2, beta, innerIter, outerIter, thresh, outerThresh, eta, gamma, betaIsZero, step, reset);

至:

linNest(X, y, &index, nrow, ncol, numGroup, rangeGroupInd, groupLen, lambda1, lambda2, beta, innerIter, outerIter, thresh, outerThresh, eta, gamma, betaIsZero, step, reset);

这使得类型匹配。

我查看了代码,linNestindex指针转发到linSolver,并且该函数根本不使用指针。也就是说,index不在您的代码中使用。我不知道这是一个错误还是故意的,但因为它没有被使用,所以进行上面的更改肯定不会有危险。您也可以只替换indexnullptr.


推荐阅读