mex compilation error running fftw3 library

3 Ansichten (letzte 30 Tage)
ado nunes
ado nunes am 30 Mai 2017
Beantwortet: Aylin am 2 Jun. 2017
Hi
I need to compile a c++ code as a mex file. It uses the library fftw3. For now I am just trying to run a simple fftw3 example code dowanloaded from
https://github.com/undees/fftw-example/blob/master/fftw_example.c
If I run it from the terminal it compiles the code:
gcc -Iusr/local/include/ -L/usr/local/lib -lfftw3 -pat_to_fftw_example.c
But if i run the same in matlab:
mex -Iusr/local/include/ -L/usr/local/lib -lfftw3 -pat_to_fftw_example.c
I get this error:
Error using mex
ld: warning: directory not found for option '-L/usr/local/opt/llvm/4.0.0_1'
Undefined symbols for architecture x86_64:
"_mexFunction", referenced from: -exported_symbol[s_list] command line option
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Anybody knows how to solve it?
Thanks

Antworten (1)

Aylin
Aylin am 2 Jun. 2017
The "Undefined symbols for architecture..._mexFunction" error is usually caused by a missing mexFunction function.
In C/C++ applications, the program entry point is usually defined using the main function which has a specific signature:
int main() {...}
int main( int argc, char *argv[] ) {...}
Similarly, the entry point in a MATLAB MEX file is defined using the mexFunction:
void mexFunction( int nlhs, mxArray *plhs[], int prhs, const mxArray *prhs[] ) {...}
https://www.mathworks.com/help/matlab/apiref/mexfunction.html
If you add a mexFunction to your 'fftw_example.c', it can be compiled with the mex command. See some of the mex examples for more information:
https://www.mathworks.com/help/matlab/matlab_external/standalone-example.html
The mex function reference page and the MATLAB matrix API reference could also help with this.

Kategorien

Mehr zu Write C Functions Callable from MATLAB (MEX Files) finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by