MATLAB: Does LOADLIBRARY fail to include the header files even when the search path has been added using the ‘includepath’ option in MATLAB

MATLAB

I have a shared library 'mylib.dll' with four header files. I created a new header file 'myheader.h' and used the '#include' directive to include all the four header files as follows:
//myheader.h
#include "first.h"
#include "second.h"
#include "third.h"
#include "fourth.h"
Then I used the LOADLIBRARY command as follows:
loadlibrary('mylib', 'myheader.h', 'mfilename', 'myproto', 'includepath', 'C:\myfiles')
where 'C:\myfiles' contains all the above header files.
The issue is that the 'myproto.m' file that gets generated is empty and it does not contain any of the defined datastructures.

Best Answer

This is expected behavior. By design, when other header files are included in the header file for the target DLL, the functions found in those headers are loaded only if an 'addheader' statement is used. One reason for this is that many headers include standard C (e.g., stdio.h) or Windows headers (e.g., windows.h) that would bring in many undesired functions with the LOADLIBRARY command.
The behavior you seek may be obtained by using the 'addheader' option to include all the additional header files as follows:
loadlibrary('mylib', 'myheader.h', 'mfilename', 'myproto', 'addheader', 'first.h',... 'addheader','second.h', 'addheader','third.h', 'addheader, 'fourth.h')
The 'myproto.m' file should then be generated appropriately.
Related Question