I am using MATLAB R2008b in Windows 7. The compiler is Lcc-win32 C 2.4.1. I tried to make an exe file from an m file which can retrieve its path and filename. A colleague gave me a C file (mlgetmodulefilename.c) and suggested me to use mcc -m XYZ.m mlgetmodulefilename.c to generate XYZ.exe
First, I got some errors regarding matlab.h. So I copied, pasted, and renamed mex.h to matlab.h. Then, I faced the following error and warning:
Warning: Name is nonexistent or not a directory: C:\Program Files\MATLAB\R2008b\toolbox\compiler\patch.
c:\users\user\appdata\local\temp\mbuild~1\mlgetmodulefilename.obj .text: undefined reference to '_mxCreateString'
Can anybody help me with this? Thank you.
mlgetmodulefilename.c
#include "matlab.h"
#include <stdio.h>
#include <windows.h>
#include "megetmodulefilename_external.h"
/*
INPUT
None
OUTPUT
None
RETURN
The full filename of the calling function
SYNOPSIS
*/
#define BUFSIZE 255
mxArray * Mmegetmodulefilename(int nargout_)
{
DWORD buflen;
TCHAR lpFilename[BUFSIZE]=TEXT("");
buflen = GetModuleFileName(NULL, lpFilename, BUFSIZE);
if (buflen == 0) {
return (mxCreateString("") );
}
else {
return (mxCreateString(lpFilename) );
}
}