From: Christine on
I'm trying to mex some fortran code for use with Simulink and I'm running into problems at the linking stage. I'm running gcc4.4.1 from Fink with Mac OS 10.6 and an Intel 64-bit processor. My code is successfully compiling as x86_64 architecture, but for some reason the linker is trying to link as i386.

mexopts.sh
----------------------------------------------------------------
-> MATLAB = /Applications/Scientific/MATLAB_R2010a.app
-> CC = /sw/bin/gcc-4
-> CC flags:
CFLAGS = -fno-common -no-cpp-precomp -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.6 -fexceptions
CDEBUGFLAGS = -g
COPTIMFLAGS = -O2 -DNDEBUG
CLIBS = -L/Applications/Scientific/MATLAB_R2010a.app/bin/maci64 -lmx -lmex -lmat -lstdc++
arguments = -DMX_COMPAT_32
-> CXX = /sw/bin/g++-4
-> CXX flags:
CXXFLAGS = -fno-common -no-cpp-precomp -fexceptions -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.6
CXXDEBUGFLAGS = -g
CXXOPTIMFLAGS = -O2 -DNDEBUG
CXXLIBS = -L/Applications/Scientific/MATLAB_R2010a.app/bin/maci64 -lmx -lmex -lmat -lstdc++
arguments = -DMX_COMPAT_32
-> FC = /sw/bin/gfortran
-> FC flags:
FFLAGS = -fdefault-real-8 -fdefault-double-8 -fexceptions -m64 -fbackslash
FDEBUGFLAGS = -g
FOPTIMFLAGS = -Os -funroll-loops -ftree-vectorize
FLIBS = -L/Applications/Scientific/MATLAB_R2010a.app/bin/maci64 -lmx -lmex -lmat -L/sw/lib/gcc4.4/lib/x86_64/ -lgfortran -L/sw/lib/gcc4.4/lib/gcc/i686-apple-darwin10/4.4.1/x86_64/ -lgfortranbegin
arguments = -DMX_COMPAT_32
-> LD = /sw/bin/gcc-4
-> Link flags:
LDFLAGS = -Wl,-twolevel_namespace -undefined error -arch x86_64 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.6 -bundle -Wl,-exported_symbols_list,/Applications/Scientific/MATLAB_R2010a.app/extern/lib/maci64/fexport.map
LDDEBUGFLAGS = -g
LDOPTIMFLAGS = -O
LDEXTENSION = .mexmaci64
arguments =
-> LDCXX =
-> Link flags:
LDCXXFLAGS =
LDCXXDEBUGFLAGS =
LDCXXOPTIMFLAGS =
LDCXXEXTENSION =
arguments =
----------------------------------------------------------------

<lines of successful compiling>

-> /sw/bin/gcc-4 -O -Wl,-twolevel_namespace -undefined error -arch x86_64 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.6 -bundle -Wl,-exported_symbols_list,/Applications/Scientific/MATLAB_R2010a.app/extern/lib/maci64/fexport.map -o "FAST_SFunc.mexmaci64" DoubPrec.o SysMatlab.o NWTC_IO.o NWTC_Num.o NWTC_Aero.o NWTC_Library.o SharedInflowDefs.o HHWind.o FFWind.o FDWind.o CTWind.o UserWind.o InflowWindMod.o SharedTypes.o AeroMods.o GenSubs.o AeroSubs.o AeroDyn.o FAST_Mods.o Noise.o fftpack.o FFTMod.o HydroCalc.o AeroCalc.o FAST_IO.o FAST.o PitchCntrl_ACH.o SetVersion.o UserSubs.o UserVSCont_KP.o FASTSimulink.o FASTGateway.o -L/Applications/Scientific/MATLAB_R2010a.app/bin/maci64 -lmx -lmex -lmat -L/sw/lib/gcc4.4/lib/x86_64/ -lgfortran -L/sw/lib/gcc4.4/lib/gcc/i686-apple-darwin10/4.4.1/x86_64/ -lgfortranbegin

ld: warning: in DoubPrec.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in SysMatlab.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in NWTC_IO.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in NWTC_Num.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in NWTC_Aero.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in NWTC_Library.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in SharedInflowDefs.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in HHWind.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in FFWind.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in FDWind.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in CTWind.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in UserWind.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in InflowWindMod.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in SharedTypes.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in AeroMods.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in GenSubs.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in AeroSubs.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in AeroDyn.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in FAST_Mods.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in Noise.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in fftpack.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in FFTMod.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in HydroCalc.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in AeroCalc.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in FAST_IO.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in FAST.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in PitchCntrl_ACH.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in SetVersion.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in UserSubs.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in UserVSCont_KP.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in FASTSimulink.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in FASTGateway.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in /Applications/Scientific/MATLAB_R2010a.app/bin/maci64/libmx.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in /Applications/Scientific/MATLAB_R2010a.app/bin/maci64/libmex.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in /Applications/Scientific/MATLAB_R2010a.app/bin/maci64/libmat.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in /sw/lib/gcc4.4/lib/x86_64//libgfortran.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in /sw/lib/gcc4.4/lib/gcc/i686-apple-darwin10/4.4.1/x86_64//libgfortranbegin.a, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in /sw/lib/gcc4.4/lib/gcc/i686-apple-darwin10/4.4.1/x86_64//libgcc.a, file was built for unsupported file format which is not the architecture being linked (i386)
Undefined symbols:
"_mexfunction_", referenced from:
-exported_symbol[s_list] command line option
ld: symbol(s) not found
collect2: ld returned 1 exit status

mex: link of ' "FAST_SFunc.mexmaci64"' failed.


Any thoughts on how to fix this?
From: Christine on
Additional info:
- Matlab 2010a 64-bits, 'computer' gives MACI64
From: Chris Turnes on
"Christine " <christine.mecklenborg(a)gmail.com> wrote in message <hu4cak$d07$1(a)fred.mathworks.com>...
> Additional info:
> - Matlab 2010a 64-bits, 'computer' gives MACI64

I'm running into the same problem. I'm using the NFFT3 and FFTW3 libraries. One solution I found online was to re-configure the libraries to make sure the architecture its compiled for is that which you're using. In my case, I have i386, so I'm re-configuring the two libraries by:
../configure CC="gcc -arch i386" CXX="g++ -arch i386"
From: Christine on
"Chris Turnes" <cturnes(a)gmail.com> wrote in message <hu6ioc$dsh$1(a)fred.mathworks.com>...

> I'm running into the same problem. I'm using the NFFT3 and FFTW3 libraries. One solution I found online was to re-configure the libraries to make sure the architecture its compiled for is that which you're using. In my case, I have i386, so I'm re-configuring the two libraries by:
> ./configure CC="gcc -arch i386" CXX="g++ -arch i386"

Yeah, but I already have the -arch tags set for x86_64, which matches my computer's architecture and the 64-bit Matlab I'm using. I'm not sure why the linker is trying for an i386 config.
From: Ben Abbott on
"Christine " <christine.mecklenborg(a)gmail.com> wrote in message <hu6o14$322$1(a)fred.mathworks.com>...

> Yeah, but I already have the -arch tags set for x86_64, which matches my computer's architecture and the 64-bit Matlab I'm using. I'm not sure why the linker is trying for an i386 config.

For a 64 bit binary add the flag "-m64". I haven't done this for mex-files with Matlab, but did need to add this option for other projects. The snippet (from the web) below explains what the various options do.

The "-m32" and "-m64" options generate code for a 32-bit or 64-bit environment. The 32-bit environment sets int, long and pointer to 32 bits and generates code that runs on any i386 system. The 64-bit environment sets int to 32 bits and long and pointer to 64 bits and generates code for AMD's x86-64 architecture. For darwin only the -m64 option turns off the -fno-pic and -mdynamic-no-pic options. -march=cpu-type Generate instructions for the machine type cpu-type. The choices for cpu-type are the same as for -mtune. Moreover, specifying -march=cpu-type implies -mtune=cpu-type. In other words, selecting -m32 does not necessarily restrict the compiler to using only instructions which are available on the i386. Selecting -march=i386 does restrict the compiler. The default -march option is determined by how the compiler was configured when it was built.