c++ - 使用 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.
我认为错误来自未正确指定变量。有人可以帮忙吗?
解决方案
错误消息告诉您“候选函数不可行:第三个参数没有从 '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);
这使得类型匹配。
我查看了代码,linNest
将index
指针转发到linSolver
,并且该函数根本不使用指针。也就是说,index
不在您的代码中使用。我不知道这是一个错误还是故意的,但因为它没有被使用,所以进行上面的更改肯定不会有危险。您也可以只替换index
为nullptr
.
推荐阅读
- java - Javax 声音采样:FloatType.Control 不支持的控件类型问题
- html - 为什么文本元素会超出 div?
- c++ - 在 C++ 优化中合并大型二进制文件
- node.js - Visual Studio 2017 Node.js 异常不起作用
- javascript - 我应该如何使用 aws-amplify Auth.sigIn 而不是 ajax 与 redux-observable 和 rxjs 6?
- python - 为什么python中字符串连接的顺序对速度影响很大?
- angular - 仅在浏览器刷新 ANGULAR 5 时才会启动的功能
- laravel - 如何让 Laravel 异步工作?
- javascript - 如果选中复选框,则仅包含/启用表单字段
- google-chrome - 如何在多个 chrome 实例上打开相同的 url