Dingess
Dingess

Reputation: 27

Matlab Compiler linking errors (64 bit versus 32 bit)

I have been using the deploytool in Matlab for the past few months in my 2010b 64bit version of Matlab. I just recently found out that I need to create a 32 bit version of my c shared library.

To do this I follow the same methods I had been using previously (pretty much calling the command mcc -W lib:MYLIB -T link:lib -d 'MYOUTPUTFOLDER' -v 'MFILE1' 'MFILE2') in my 2009b 32 version of Matlab. I keep getting the error LNK1811: cannot open input file LIBRARY.obj. I have tried to find this LIBRARY object file but I cannot seem to find it anywhere.

So far I have checked to ensure all of the correct libraries are available (found at $MATLABROOT$\extern\include\win32), I have made sure all of my paths are correct in the compopts.bat file, and I have used the option -T compile:lib which works fine and creates a dll. This would be great but I need a lib file to use later in mbuild.

My current path forward is to take the compopts from my 64 bit version of Matlab (on a different machine) and compare it with my compopts for the 32 bit. I will post if it makes a difference.

Upvotes: 1

Views: 656

Answers (1)

CitizenInsane
CitizenInsane

Reputation: 4865

To summarize our comments in the question and make it an answer. Here is how I manage to create both x32 and x64 libraries/standalones with mcc.

NB: Maybe there are more elegant solutions to configure deploytool, anyway with brute force I'm sure it works and I can automate global deployment process for my applications ...

Machine setup

  1. Install Matlab x32 and x64 on your machine
  2. Run Matlab x32 and setup compiler options typing msbuild -setup

    • This will generate a compopts.bat file in ~user\AppData\Roaming\MathWorks\MATLAB\R2013b (path may differ upon your version)
    • Rename this file to compopts.x32.bat (see later)
  3. Run Matlab x64 and setup compiler options typing msbuild -setup

    • This will generate a compopts.bat file in ~user\AppData\Roaming\MathWorks\MATLAB\R2013b (!!Overwrites x32!!)
    • Rename this file to compopts.x64.bat (To workaround file overwrite)

EDIT Just tested ... In R2014b, Matlab does no longer overwrites same compots.bat file ... it now generates two separate MBUILD_C++_win64.xml and MBUILD_C++_win32.xml files (which is a good thing!).

Compilation in x32

Force your compilation script to point to ~matlabx32\bin\win32\mcc.exe and force mcc.exe to use previously saved compopts.x32.bat file using the -f option. Your command line should be something like:

~matlabx32\bin\win32\mcc.exe -f "compopts.x32.bat"  ... other mcc options ... 

Compilation in x64

Force your compilation script to point to ~matlabx64\bin\win64\mcc.exe and force mcc.exe to use previously saved compopts.x64.bat file using the -f option. Your command line should be something like:

~matlabx64\bin\win64\mcc.exe -f "compopts.x64.bat"  ... other mcc options ... 

Upvotes: 1

Related Questions