0
votes

I want to load static library into MATLAB. It is impossible to do with loadlibrary function, so I wrote mexfunction where I have placed entry point for the function from my static library. Then I want to create mex file with:

mex -v  -Iinclude -Iusr/include mex_func.c libmy_lib.a

Header files are stored in include folder (inside current working directory) and header files from some standard libraries used by my libmy_lib.a (like FFTW) are stored in usr/include folder. As a result, I get error:

collect2: error: ld returned 1 exit status

where all erros are induced by undefined reference to FFTW functions. What is wrong here?

1

1 Answers

0
votes

According to the Matlab documentation you will have to prefix the library with a -l, you do not specifiy the extension and you also drop the first lib. If the library is not on the system search path, you can also specify a library search path with the -L option, before specifying the library. Also, the file to be compiled usually goes last in the mex statement.

mex -v  -Iinclude -Iusr/include -Lusr/path_to_my_libfile -lmy_lib  mex_func.c 

I am not sure if this already solves your problem, but it might help.