I am testing to call another function in my mex file. But I came across a building error. " "void __cdecl transferarray1(struct mxArray_tag const *,class std::vector > &)" (??$transferarray1@H@@YAXPEBUmxArray_tag@@AEAV?$vector@HV?$allocator@H@std@@@std@@@Z) test.mexw64 : fatal error LNK1120" My code is below: test.cpp:
#include "mex.h"
#include <vector>
#include "inoutmex.h"
using namespace std;
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
vector<int> idx;
transferarray1(prhs[0],idx);
}
inoutmex.cpp
#include "mex.h"
#include <vector>
using namespace std;
template <typename T>
void transferarray1(const mxArray *ix, vector<T>&V)
{
mwSize num = mxGetNumberOfElements(ix);
mxDouble *ptr;
ptr = mxGetPr(ix);
for (int i = 0; i < (int)num; i++)
{
V.push_back(T(*ptr++));
}
}
inoutmex.h
#include "mex.h"
#include <vector>
using namespace std;
template <typename T>
void transferarray1(const mxArray *ix, vector<T>&V);
These 3 files are all under one directory. I think it must be related to link problem.
I ran the command mex test.cpp
in matlab command line. It gives the link error. Any suggestion will be appreciate.