Thread Subject: Cannot mex with gfortran on Snow Leopard (64bit)

Subject: Cannot mex with gfortran on Snow Leopard (64bit)

From: Geico Caveman

Date: 17 Oct, 2009 10:59:38

Message: 1 of 5

Platform: Mac OSX 10.6.1

Matlab version: R2009a (so this is 32 bit)

gfortran version:

$ gfortran --version
GNU Fortran (GCC) 4.5.0 20090910 (experimental)

I downloaded this version from HPC on sourceforge.

When I try to compile mexFunction.f90, I get:

$ /Applications/MATLAB2009a/MATLAB_R2009a.app/bin/mex -v -maci mexFunction.f90
-> mexopts.sh sourced from directory (DIR = $HOME/.matlab/$REL_VERSION)
   FILE = /Users/madhusudan/.matlab/R2009a/mexopts.sh
----------------------------------------------------------------
-> MATLAB = /Applications/MATLAB2009a/MATLAB_R2009a.app
-> CC = gcc-4.0
-> 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 = g++-4.0
-> 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 = 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 = gcc-4.0
-> 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 =
----------------------------------------------------------------

-> 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"

-> gcc-4.0 -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 mexFunction.o, file is not of required architecture
ld: warning: in
/Developer/SDKs/MacOSX10.5.sdk/usr/local/lib/libgfortran.dylib, file is
not of required architecture
ld: warning: in
/Developer/SDKs/MacOSX10.5.sdk/usr/local/lib/gcc/x86_64-apple-darwin10/4.5.0/libgfortranbegin.a,
file is not of required architecture
ld: warning: in
/Developer/SDKs/MacOSX10.5.sdk/usr/local/lib/gcc/x86_64-apple-darwin10/4.5.0/libgcc.a,
file is not of required architecture
Undefined symbols:
  "_mexfunction_", referenced from:
     -exported_symbols_list command line option
ld: symbol(s) not found
collect2: ld returned 1 exit status

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

No change if I drop the -maci flag.

What is wrong here ?

Subject: Cannot mex with gfortran on Snow Leopard (64bit)

From: Geico Caveman

Date: 17 Oct, 2009 11:22:57

Message: 2 of 5

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 ?

Subject: Cannot mex with gfortran on Snow Leopard (64bit)

From: Janus Weil

Date: 18 Oct, 2009 14:01:56

Message: 3 of 5


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

Try -m32.

Cheers,
Janus

Subject: Cannot mex with gfortran on Snow Leopard (64bit)

From: Geico Caveman

Date: 19 Oct, 2009 06:20:21

Message: 4 of 5

On 2009-10-18 07:01:56 -0700, Janus Weil <jaydub66@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.

Subject: Cannot mex with gfortran on Snow Leopard (64bit)

From: Robert

Date: 18 Feb, 2010 23:23:19

Message: 5 of 5

I'm having similar problems. I think I also need to get gfortran to generate 32bit code (since I'm running 32bit Matlab).

Where did you put the -m32 option? Somewhere in the mexopts.sh file presumably. I tried adding it to FFLAGS to no avail.

Also, what did you set FC_LIBDIR and FC_LIBDIR2 to in the mexopts.sh file?
Did you change FLIBS at all?

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com