无法导出mexfunction:符号未定义的collect.exe2.exe:错误:ld返回1退出状态

Cannot export mexFunction: symbol not defined collect2.exe: error: ld returned 1 exit status

本文关键字:ld exe 错误 返回 状态 退出 exe2 mexfunction 符号 未定义 collect      更新时间:2023-10-16

i使用matlab r2017a,当我使用'mex pq_demo.cpp'编译C 文件时,它会出现错误:

无法导出mexFunction:未定义的符号
collect2.exe:错误:ld返回1退出状态

我的mexfunction在pq_create.cpp中:

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
    // read the parameters
    // check input
    if( nrhs != 1 || !mxIsNumeric(prhs[0]) )
        mexErrMsgTxt("A unique scalar number with the expected size of the queue is necessary.n");
    // retrieve the data
    int nelems = 100;
    retrieve_data( prhs[0], nelems );
    // instantiate the priority queue
    MaxHeap<double>* pq = new MaxHeap<double>(nelems);
    // convert the points to double
    plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);
    double* pointer_to_tree = mxGetPr(plhs[0]);
    pointer_to_tree[0] = (long long) pq;
}

所以,我该如何解决错误。谢谢!

您应该首先包括头文件mex.h,例如#include mex.h