mex compilation error running fftw3 library

조회 수: 3 (최근 30일)
ado nunes
ado nunes 2017년 5월 30일
답변: Aylin 2017년 6월 2일
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