From: Geico Caveman on
Just had a thought that maybe the gcc version is from Xcode (3.2) and
gfortran is from the later branch.

So, I got gcc from HPC (which also contains gfortran), so now the two
versions are in sync after fixing the paths in mexopts.sh:

$ /Applications/MATLAB2009a/MATLAB_R2009a.app/bin/mex -v -maci mexFunction.f90
-> mexopts.sh sourced from directory (DIR = $HOME/.matlab/$REL_VERSION)
FILE = /Users/geicocaveman/.matlab/R2009a/mexopts.sh
----------------------------------------------------------------
-> MATLAB = /Applications/MATLAB2009a/MATLAB_R2009a.app
-> CC = /usr/local/bin/gcc
-> CC flags:
CFLAGS = -fno-common -no-cpp-precomp -arch i386
-isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5
-fexceptions
CDEBUGFLAGS = -g
COPTIMFLAGS = -O2 -DNDEBUG
CLIBS =
-L/Applications/MATLAB2009a/MATLAB_R2009a.app/bin/maci -lmx -lmex -lmat
-lstdc++
arguments = -DMX_COMPAT_32
-> CXX = /usr/local/bin/g++
-> CXX flags:
CXXFLAGS = -fno-common -no-cpp-precomp -fexceptions
-arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk
-mmacosx-version-min=10.5
CXXDEBUGFLAGS = -g
CXXOPTIMFLAGS = -O2 -DNDEBUG
CXXLIBS =
-L/Applications/MATLAB2009a/MATLAB_R2009a.app/bin/maci -lmx -lmex -lmat
-lstdc++
arguments = -DMX_COMPAT_32
-> FC = /usr/local/bin/gfortran
-> FC flags:
FFLAGS = -fexceptions -fbackslash -mtune=i686
FDEBUGFLAGS = -gdwarf-2
FOPTIMFLAGS = -O3 -ftree-vectorize
FLIBS =
-L/Applications/MATLAB2009a/MATLAB_R2009a.app/bin/maci -lmx -lmex -lmat
-L/usr/local/lib/gcc/x86_64-apple-darwin10/4.5.0/../../.. -lgfortran
-L/usr/local/lib/gcc/x86_64-apple-darwin10/4.5.0 -lgfortranbegin
arguments = -DMX_COMPAT_32
-> LD = /usr/local/bin/gcc
-> Link flags:
LDFLAGS = -Wl,-twolevel_namespace -undefined error
-arch i386 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk
-mmacosx-version-min=10.5 -bundle
-Wl,-exported_symbols_list,/Applications/MATLAB2009a/MATLAB_R2009a.app/extern/lib/maci/fexport.map


LDDEBUGFLAGS = -g
LDOPTIMFLAGS = -O
LDEXTENSION = .mexmaci
arguments =
-> LDCXX =
-> Link flags:
LDCXXFLAGS =
LDCXXDEBUGFLAGS =
LDCXXOPTIMFLAGS =
LDCXXEXTENSION =
arguments =
----------------------------------------------------------------

-> /usr/local/bin/gfortran -c
-I/Applications/MATLAB2009a/MATLAB_R2009a.app/extern/include
-I/Applications/MATLAB2009a/MATLAB_R2009a.app/simulink/include
-fexceptions -fbackslash -mtune=i686 -DMX_COMPAT_32 -O3
-ftree-vectorize "mexFunction.f90"

-> /usr/local/bin/gcc -O -Wl,-twolevel_namespace -undefined error -arch
i386 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk
-mmacosx-version-min=10.5 -bundle
-Wl,-exported_symbols_list,/Applications/MATLAB2009a/MATLAB_R2009a.app/extern/lib/maci/fexport.map
-o "mexFunction.mexmaci" mexFunction.o
-L/Applications/MATLAB2009a/MATLAB_R2009a.app/bin/maci -lmx -lmex -lmat
-L/usr/local/lib/gcc/x86_64-apple-darwin10/4.5.0/../../.. -lgfortran
-L/usr/local/lib/gcc/x86_64-apple-darwin10/4.5.0 -lgfortranbegin

ld: warning: in
/Applications/MATLAB2009a/MATLAB_R2009a.app/bin/maci/libmx.dylib, file
is not of required architecture
ld: warning: in
/Applications/MATLAB2009a/MATLAB_R2009a.app/bin/maci/libmex.dylib, file
is not of required architecture
ld: warning: in
/Applications/MATLAB2009a/MATLAB_R2009a.app/bin/maci/libmat.dylib, file
is not of required architecture
Undefined symbols:
"_mxgetm_", referenced from:
_mexfunction_ in mexFunction.o
"_mexerrmsgtxt_", referenced from:
_mexfunction_ in mexFunction.o
"_mxgetn_", referenced from:
_mexfunction_ in mexFunction.o
"_mxcreatedoublematrix_", referenced from:
_mexfunction_ in mexFunction.o
"_scalarmult_", referenced from:
_mexfunction_ in mexFunction.o
"_mxgetscalar_", referenced from:
_mexfunction_ in mexFunction.o
"_mxgetpr_", referenced from:
_mexfunction_ in mexFunction.o
_mexfunction_ in mexFunction.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

mex: link of ' "mexFunction.mexmaci"' failed.

What gives ? How do I generate 32 bit code from gcc and gfortran ? The
errors above seem to indicate a problem with the mex libraries in
Matlab (32 bit architecture, I am guessing).

If I try the -march=i686 option with gfortran, I get the following
error with one of the pure fortran source files:

$ gfortran -march=i686 -O3 -ftree-vectorize -c matlabmex.f90
f951: error: CPU you selected does not support x86-64 instruction set

Does this mean that it is impossible to use mex with R2009a on Snow Leopard ?

From: Janus Weil on

> What gives ? How do I generate 32 bit code from gcc and gfortran ?

Try -m32.

Cheers,
Janus
From: Geico Caveman on
On 2009-10-18 07:01:56 -0700, Janus Weil <jaydub66(a)googlemail.com> said:

>
>> What gives ? How do I generate 32 bit code from gcc and gfortran ?
>
> Try -m32.
>
> Cheers,
> Janus

That worked. Thanks. I was trying -march=i386 without avail.