0

say, if choose mexopts.sh as the configuration files for mex,

then how does mex decide which option listed in the mexopts.sh is used for compiling?

for example, using 32bit matlab on 64bit mac os x: mexopts.sh looks like:

 ,,maci
 ........

 ,,maci64
 ......

Then, maci or maci64 is used when compiling?

What commands or way can I do in order to compile 32bit lib instead of 64bit lib?

Further explanation of my process and the error message I got : I am using mac os x 10.8 (64bit) with matlab R2010a (32bit) to produce a binary mex-file. The Xcode is 4.6 version, I installed Command Line Tools on my machine. Then I downloaded the patch from matlab for 2011 and 2012 version anyway. (if I don't install the patch, I got a lot of link errors saying some header files are missing). After I installed the patch ( I believe it changes my mexopts.sh file), when I run mex a.cpp, I got error message saying that /Applications/MATLAB_R2010a.app/bin/maci64 cannot be found. Of course, it cannot find the maci64 folder, it is 32bit, there is only maci folder. So Anyone knows what I should do in order to make matlab look for maci folder instead of maci64 folder? Thanks a lot!

user1558064
  • 867
  • 3
  • 12
  • 28

3 Answers3

2

MATLAB does not support cross compilation of MEX files. So your 32-bit MATLAB installation should be producing 32-bit MEX files even though the OS is 64-bit.

Also, from the article I've linked

Further, beginning with R2010b, a 32-bit version of MATLAB is no longer produced for the Mac.

If you're running R2010b or later, your MATLAB is not 32-bit anyway.

To see what switches the MEX script is invoking the compiler with, use the -v option.

You can also use the file tool to check whether the generated binary is 32 or 64-bit.

Community
  • 1
  • 1
Praetorian
  • 106,671
  • 19
  • 240
  • 328
  • MATLAB does not support cross compilation of MEX files. So your 32-bit MATLAB installation should be producing 32-bit MEX files even though the OS is 64-bit. ---- So it means , if I give mex a.cpp , it will generate 32bit version anyway? But when I gave something like mex a.cpp, I got an error message saying , can not find /Applications/MATLAB_R2012a.app/bin/maci64. Apparently, for 32bit matlab (R2010a), there is no maci64 folder, there is only maci folder. Why do I get this error message? Should I do something like: mex -arch maci a.cpp? What do I do wrong? Thanks. – user1558064 May 08 '13 at 13:22
  • @user1558064 Unfortunately I've never used MATLAB on a Mac, so I'm not going to be of much help when it comes to specific issues such as that error. You could try the `-arch` option; also add the `-v` switch and look at the flags that are being passed to the compiler. That should help you determine whether the output binary is intended to be 32 or 64 bit. – Praetorian May 08 '13 at 14:21
1

As its been explained, MATLAB produces MEX files of the same bit-ness as itself, not that of the OS. This is true at least on Windows with recent MATLAB versions, where you can have either 32-bit or 64-bit MATLAB running on 64-bit Windows. Other platforms are moving towards 64-bit versions only.

Here is another way to get the configured mex switches:

>> cc = mex.getCompilerConfigurations
>> cc.Details

In my case I get:

>> cc = mex.getCompilerConfigurations
cc = 
  CompilerConfiguration with properties:

             Name: 'Microsoft Visual C++ 2010'
     Manufacturer: 'Microsoft'
         Language: 'C++'
          Version: '10.0'
         Location: 'C:\Program Files\Microsoft Visual Studio 10.0'
          Details: [1x1 mex.CompilerConfigurationDetails]
       LinkerName: 'Microsoft Visual C++ 2010'
    LinkerVersion: '10.0'
>> cc.Details
ans = 
  CompilerConfigurationDetails with properties:

         CompilerExecutable: 'cl'
              CompilerFlags: [1x115 char]
          OptimizationFlags: '/O2 /Oy- /DNDEBUG'
                 DebugFlags: '/Z7'
           LinkerExecutable: 'link'
                LinkerFlags: [1x327 char]
    LinkerOptimizationFlags: ''
           LinkerDebugFlags: '/debug /PDB:"%OUTDIR%%MEX_NAME%%MEX_EXT%.pdb"'
Amro
  • 123,847
  • 25
  • 243
  • 454
0

To answer my own question, just for those who may be interested in it,

I checked the contents of mexopts.sh and modified the part for maci (specifically set ARCH=i386) , then compile. The error message is gone.

user1558064
  • 867
  • 3
  • 12
  • 28