I tried to write my own C/C++ codes for Matlab using the Mex compiler. My challenge was to use MinGW and third party libraries.
First Matlab's Mex compiler doesn't support that. After searching the web, everyone will find the GnuMex project which can be used to that. My main problem was and I still don't know why, I couldn't use my own programmed libraries. Somehow the -L and -l command doesn't work. The Mex compiler with the help of GnuMex couldn't help me. Maybe because I'm using a 64 bit Windows 7.
Anyway, here is my fix:
Don't use them at all !
- Create a shared library project. The suffix should be changed to .mexw32.
- Use additionally to your include paths this one: C:\MATLAB\R2007b\extern\include. Change the path to your Matlab installation folder of course.
- Use additionally to your library paths this one: C:\MATLAB\R2007b\bin\win32. Don't use the on in this folder: C:\MATLAB\R2007b\\extern\lib\win32\microsoft. Here goes the same. Change the path to your Matlab installation folder.
- Add the following libraries to your project: mex, mat, mx. As you already know we don't have to use the prefix lib, for example libmex.dll. The GCC linker will do that for you. Just use it without the prefix and the -l command.
- Use for the C/C++ Preprocessor the define macro MATLAB_MEX_FILE