Clear Filters
Clear Filters

Matlab mex cpp, vectors supported?

4 views (last 30 days)
Mat Fan
Mat Fan on 27 Sep 2017
Answered: Infinite_king on 27 Mar 2024
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

Answers (1)

Infinite_king
Infinite_king on 27 Mar 2024
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,

Community Treasure Hunt

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

Start Hunting!