0
votes

Up to version 2013a I had no problem to compile, link and run my C-gateway and Fortran-source mixed mex functions (Windows, Linux and Mac). Compiling and linking went ok on R2014a-maci64 but when I try to run the resulting mex function I received the following msg:

Invalid MEX-file '/Users/name/MATLAB/mexaci64_R2014a/xxxx.mexmaci64':
dlopen(/Users/name/MATLAB/mexaci64_R2014a/xxxx.mexmaci64, 6): Symbol not found:
__gfortran_transfer_character_write
Referenced from: /Users/name/MATLAB/mexaci64_R2014a/xxxx.mexmaci64
Expected in: /Applications/MATLAB_R2014a.app/sys/os/maci64/libgfortran.3.dylib
in /Users/name/MATLAB/mexaci64_R2014a/xxxx.mexmaci64

The first thing I have found out is that libgfortran.3.dylib that comes with matlab does not seem to have __gfortran_transfer_character_write (Could someone check this too, please?), since the command

nm libgfortran.3.dylib | grep __gfortran_transfer_character_write

showns nothing.

I have replaced the entire maci64 dir with new libraries (say from gfortran 4.9.1 or 4.8.2) to get

nm libgfortran.3.dylib | grep __gfortran_transfer_character_write
00000000000c7210 T __gfortran_transfer_character_write 

which means there is something there ("T" The symbol is in the text (code) section). However if I re-compile my mixed mex function again (of course with the new gfortran compiler and the right paths), the error msg is still there.

Fortran write command (example write(6,*)) seems to be the problem since all other mixed mex functions that do not have a fortran write work.

Can someone point out what I am doing wrong?

Thank you very much

Ed

gfortran -c -I/Applications/MATLAB_2014a.app/extern/include -I/Applications/MATLAB_2014a.app/simulink/include -fexceptions -m64 -fbackslash  -DMX_COMPAT_32 -O sourcef1.f
gfortran -c -I/Applications/MATLAB_2014a.app/extern/include -I/Applications/MATLAB_2014a.app/simulink/include -fexceptions -m64 -fbackslash  -DMX_COMPAT_32 -O sourcef2.f

mex -v -O -compatibleArrayDims  sourcef1g.c sourcef1.o correl.o -L/Users/name/Downloads/tmp/usr/local/lib -lgfortran -L/Users/name/Downloads/tmp/usr/local/lib/gcc/x86_64-apple-darwin13.1.0/4.9.0 -lgfortranbegin
Verbose mode is on.
... Looking for compiler 'Xcode with Clang' ...
... Executing command 'xcode-select -print-path' ...Yes ('/Applications/Xcode.app/Contents/Developer').
... Looking for folder '/Applications/Xcode.app/Contents/Developer' ...Yes.
... Executing command 'which xcrun' ...Yes ('/usr/bin/xcrun').
... Looking for folder '/usr/bin' ...Yes.
... Executing command 'defaults read com.apple.dt.Xcode IDEXcodeVersionForAgreedToGMLicense' ...No.
... Executing command 'defaults read /Library/Preferences/com.apple.dt.Xcode IDEXcodeVersionForAgreedToGMLicense' ...Yes ('5.1').
... Executing command '
agreed=5.1 
 if echo $agreed | grep -E '[\.\"]' >/dev/null; then 
 lhs=`expr "$agreed" : '\([0-9]*\)[\.].*'` 
  rhs=`expr "$agreed" : '[0-9]*[\.]\(.*\)$'` 
 if echo $rhs | grep -E '[\."]' >/dev/null; then 
 rhs=`expr "$rhs" : '\([0-9]*\)[\.].*'` 
 fi 
 if [ $lhs -gt 4 ] || ( [ $lhs -eq 4 ] && [ $rhs -ge 3 ] ); then 
 echo $agreed 
 else 
 exit 1
 fi 
 fi' ...Yes ('5.1').
... Executing command 'xcode-select -print-path' ...Yes ('/Applications/Xcode.app/Contents/Developer').
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk' ...No.
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk' ...Yes.
... Executing command 'xcode-select -print-path' ...Yes ('/Applications/Xcode.app/Contents/Developer').
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk' ...No.
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk' ...Yes.
... Executing command 'echo /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk | rev | cut -c1-10 | rev | egrep -oh '[0-9]+\.[0-9]+'' ...Yes ('10.8').
Found installed compiler 'Xcode with Clang'.
Options file details
-------------------------------------------------------------------
    Compiler location: /Applications/Xcode.app/Contents/Developer
    Options file: /Users/name/.matlab/R2014a/mex_C_maci64.xml
    CMDLINE100 : /usr/bin/xcrun -sdk macosx10.8 clang -c -DMX_COMPAT_32   -DMATLAB_MEX_FILE -I"/Applications/MATLAB_R2014a.app/extern/include" -I"/Applications/MATLAB_R2014a.app/simulink/include" -fno-common -arch x86_64 -mmacosx-version-min=10.8 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -O2 -DNDEBUG /Users/name/MATLAB/mexaci64_R2014a/sourcef1g.c -o /var/folders/2x/9tfgl3sn1gq0kl_l9yl5q00c0000gn/T//mex_17182455108154_3778/sourcef1g.o
    CMDLINE200 : /usr/bin/xcrun -sdk macosx10.8 clang -Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.8 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -bundle  -Wl,-exported_symbols_list,"/Applications/MATLAB_R2014a.app/extern/lib/maci64/mexFunction.map" /var/folders/2x/9tfgl3sn1gq0kl_l9yl5q00c0000gn/T//mex_17182455108154_3778/sourcef1g.o sourcef1.o correl.o -O -Wl,-exported_symbols_list,"/Applications/MATLAB_R2014a.app/extern/lib/maci64/mexFunction.map"  -lgfortran  -lgfortranbegin   -L/Users/name/Downloads/tmp/usr/local/lib  -L/Users/name/Downloads/tmp/usr/local/lib/gcc/x86_64-apple-darwin13.1.0/4.9.0   -L"/Applications/MATLAB_R2014a.app/bin/maci64" -lmx -lmex -lmat -lstdc++ -o sourcef1g.mexmaci64
    CMDLINE300 : rm -f /var/folders/2x/9tfgl3sn1gq0kl_l9yl5q00c0000gn/T//mex_17182455108154_3778/sourcef1g.o
    CC : /usr/bin/xcrun -sdk macosx10.8 clang
    DEFINES : -DMX_COMPAT_32   -DMATLAB_MEX_FILE
    MATLABMEX : -DMATLAB_MEX_FILE
    CFLAGS : -fno-common -arch x86_64 -mmacosx-version-min=10.8 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk
    INCLUDE : -I"/Applications/MATLAB_R2014a.app/extern/include" -I"/Applications/MATLAB_R2014a.app/simulink/include"
    COPTIMFLAGS : -O2 -DNDEBUG
    CDEBUGFLAGS : -g
    LD : /usr/bin/xcrun -sdk macosx10.8 clang
    LDFLAGS : -Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.8 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -bundle  -Wl,-exported_symbols_list,"/Applications/MATLAB_R2014a.app/extern/lib/maci64/mexFunction.map"
    LDBUNDLE : -bundle 
    LINKEXPORT : -Wl,-exported_symbols_list,"/Applications/MATLAB_R2014a.app/extern/lib/maci64/mexFunction.map"
    LINKLIBS : -lgfortran  -lgfortranbegin   -L/Users/name/Downloads/tmp/usr/local/lib  -L/Users/name/Downloads/tmp/usr/local/lib/gcc/x86_64-apple-darwin13.1.0/4.9.0   -L"/Applications/MATLAB_R2014a.app/bin/maci64" -lmx -lmex -lmat -lstdc++
    LDOPTIMFLAGS : -O
    LDDEBUGFLAGS : -g
    OBJEXT : .o
    LDEXT : .mexmaci64
    XCODE_DIR : /Applications/Xcode.app/Contents/Developer
    XCRUN_DIR : /usr/bin
    XCODE_AGREED_VERSION : 5.1
    ISYSROOT : /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk
    SDKVER : 10.8
    MATLABROOT : /Applications/MATLAB_R2014a.app
    ARCH : maci64
    SRC : /Users/name/MATLAB/mexaci64_R2014a/sourcef1g.c
    OBJ : /var/folders/2x/9tfgl3sn1gq0kl_l9yl5q00c0000gn/T//mex_17182455108154_3778/sourcef1g.o
    OBJS : /var/folders/2x/9tfgl3sn1gq0kl_l9yl5q00c0000gn/T//mex_17182455108154_3778/sourcef1g.o sourcef1.o correl.o
    SRCROOT : /Users/name/MATLAB/mexaci64_R2014a/sourcef1g
    DEF : /var/folders/2x/9tfgl3sn1gq0kl_l9yl5q00c0000gn/T//mex_17182455108154_3778/sourcef1g.def
    EXP : sourcef1g.exp
    LIB : sourcef1g.lib
    EXE : sourcef1g.mexmaci64
    ILK : sourcef1g.ilk
    MANIFEST : sourcef1g.mexmaci64.manifest
    TEMPNAME : sourcef1g
    EXEDIR : 
    EXENAME : sourcef1g
    OPTIM : -O2 -DNDEBUG
    LINKOPTIM : -O
-------------------------------------------------------------------
Building with 'Xcode with Clang'.
/usr/bin/xcrun -sdk macosx10.8 clang -c -DMX_COMPAT_32   -DMATLAB_MEX_FILE -I"/Applications/MATLAB_R2014a.app/extern/include" -I"/Applications/MATLAB_R2014a.app/simulink/include" -fno-common -arch x86_64 -mmacosx-version-min=10.8 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -O2 -DNDEBUG /Users/name/MATLAB/mexaci64_R2014a/sourcef1g.c -o /var/folders/2x/9tfgl3sn1gq0kl_l9yl5q00c0000gn/T//mex_17182455108154_3778/sourcef1g.o


/usr/bin/xcrun -sdk macosx10.8 clang -Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.8 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -bundle  -Wl,-exported_symbols_list,"/Applications/MATLAB_R2014a.app/extern/lib/maci64/mexFunction.map" /var/folders/2x/9tfgl3sn1gq0kl_l9yl5q00c0000gn/T//mex_17182455108154_3778/sourcef1g.o sourcef1.o correl.o -O -Wl,-exported_symbols_list,"/Applications/MATLAB_R2014a.app/extern/lib/maci64/mexFunction.map"  -lgfortran  -lgfortranbegin   -L/Users/name/Downloads/tmp/usr/local/lib  -L/Users/name/Downloads/tmp/usr/local/lib/gcc/x86_64-apple-darwin13.1.0/4.9.0   -L"/Applications/MATLAB_R2014a.app/bin/maci64" -lmx -lmex -lmat -lstdc++ -o sourcef1g.mexmaci64
rm -f /var/folders/2x/9tfgl3sn1gq0kl_l9yl5q00c0000gn/T//mex_17182455108154_3778/sourcef1g.o
MEX completed successfully.

mv -f sourcef1g.mexmaci64 sourcef1.mexmaci64
1
Show the commands you use for the compile and link. Try the -v argument to see the details.Vladimir F
I have added the commands on the original msg but unfortunately I do not know how to format themuser3749165
Just a note - I have managed to have the same mixed functions compiled on windows 64.user3749165

1 Answers

1
votes

Actually, MATLAB (or MEX) does not support gfortran with version higher than 4.3.x, according to this page: Supported and Compatible Compilers – Release 2014a.

I have met exactly the same problem before. After I switched to gfortran-mp-4.3, problem solved.