mex compilation error running fftw3 library

9 次查看(过去 30 天)
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

回答(1 个)

Aylin
Aylin 2017-6-2
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.

类别

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