mex compilation error running fftw3 library

9 vues (au cours des 30 derniers jours)
ado nunes
ado nunes le 30 Mai 2017
Réponse apportée : Aylin le 2 Juin 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

Réponses (1)

Aylin
Aylin le 2 Juin 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.

Catégories

En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by