Matlab mex cpp, vectors supported?

4 次查看(过去 30 天)
Mat Fan
Mat Fan 2017-9-27
Hello,
I am trying to make a mex version of my current C-code, but can't make it compile.
The error I get is
Error using mex /tmp/mex_1395441668808765_33919/mex.o: In function `mexFunction': mex.cpp:(.text+0x2c0): undefined reference to `myFunctionName(unsigned int, std::vector<std::complex<double>, std::allocator<std::complex<double> > >&, std::vector<std::complex<double>, std::allocator<std::complex<double> > >&, unsigned int, int, bool, bool)' collect2: error: ld returned 1 exit status
The header file includes the link to the to the function with the following definition: void myFunctionName( unsigned var1, std::vector<std::complex<double>> &var2, std::vector<std::complex<double>> &var3, unsigned var4, int var5, bool var6, bool var7 );
It seems that both definitions to not match. What am I doing wrong? are vectors supported in matlab mex?
Thank you

回答(1 个)

Infinite_king
Infinite_king 2024-3-27
Hi Mat Fan,
Yes, vectors are supported in MEX. If you want to generate a MEX file from C or C++ code and run it in MATLAB, the C file should be written using the "C MATRIX API" and the "MATLAB DATA API" for C++.
Please refer to the following resource for guidance on writing a C or C++ source file in order to compile it into a MEX file,
In this case, it seems like there was another function with the same name but different function definitions. Make sure to use the standard gateway function. Within this gateway function, you can call your custom functions.
For more information, refer the following resources,

类别

Help CenterFile Exchange 中查找有关 Write C Functions Callable from MATLAB (MEX Files) 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by