From: Jörn R on
Hi,

I want to use the MinGW compiler with Matlab under windows. So I installed GNUmex and tried to compile this simple program:

#include <iostream>
#include <stdio.h>
#include "mex.h"
using namespace std;

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray*prhs[]){
printf("TEST\r\n");
cout << "TEST123" << endl;
return;
}

But when I run the compiled program with "main('')" I only get this output:

>> main('')
TEST

So the second output with "cout" which is c++ doesn't get displayed. What could be the problem?

This is the output of "mex main.cpp -v":

-> Default options filename found in C:\Uni\pdcom-3.0.1\example
----------------------------------------------------------------
-> Options file = C:\Uni\pdcom-3.0.1\example\mexopts.bat
MATLAB = C:\PROGRA~1\MATLAB\R2008a
-> COMPILER = g++
-> Compiler flags:
COMPFLAGS = -c -DMATLAB_MEX_FILE -Wall
OPTIMFLAGS = -O3
DEBUGFLAGS = -g3
arguments =
Name switch = -o
-> Pre-linking commands =
-> LINKER =
C:\PROGRA~1\MATLAB\R2008a\sys\perl\win32\bin\perl.exe
c:\uni\gnumex\linkmex.pl
-> Link directives:
LINKFLAGS = -LC:\Uni\GNUMEX~1 GM_ISCPP
LINKDEBUGFLAGS = -g -Wl,--image-base,0x28000000\n
LINKFLAGSPOST =
Name directive = -o main.mexw32
File link directive =
Lib. link directive =
Rsp file indicator =
-> Resource Compiler =
C:\PROGRA~1\MATLAB\R2008a\sys\perl\win32\bin\perl.exe
c:\uni\gnumex\rccompile.pl -o mexversion.res
-> Resource Linker =
----------------------------------------------------------------


-->
g++ -c -DMATLAB_MEX_FILE -Wall -oC:\DOKUME~1\Joern\LOKALE~1\Temp\mex_ifYYLT\main.obj
-IC:\PROGRA~1\MATLAB\R2008a\extern\include -IC:\PROGRA~1\MATLAB\R2008a\simulink\include
-O3 -DMX_COMPAT_32 C:\Uni\pdcom-3.0.1\example\main.cpp


--> C:\PROGRA~1\MATLAB\R2008a\sys\perl\win32\bin\perl.exe
c:\uni\gnumex\linkmex.pl -o main.mexw32 -LC:\Uni\GNUMEX~1 GM_ISCPP -s
C:\DOKUME~1\Joern\LOKALE~1\Temp\mex_ifYYLT\main.obj

link command: g++ -shared C:\Uni\GNUMEX~1\mex.def -o
main.mexw32 -LC:\Uni\GNUMEX~1 -s
C:\DOKUME~1\Joern\LOKALE~1\Temp\mex_ifYYLT\main.obj -llibmx -llibmex -llibmat


Regards, Joern
From: Richard Hindmarsh on
I'm not sure that "printf" or "cout" work in mex files in a predictable way. You are supposed to use "mexPrintf", which has syntax like "printf".