I am currently building a 32-bit MatLab-engine application in c++ on a 64 bit machine, with 64-bit MatLab installed. However, I do have all the dll's and library files in 32-bit for the MatLab engine. The library files and dll's are loaded correctly (I can compile and start the application without getting any errors I would get when I use the 64-bit dll's/libs), but the 32-bit dll's apparently launch the 64-bit matlab executable, so my program crashes as soon as I try to do something with the engine. Is there a way I can make my application launch the 32-bit matlab executable instead of the 32-bit one?
Thanks in advance!
Direct link to this answer If you are running MATLAB without the desktop interface, the information appears in the command window when MATLAB starts. This will return win64 for 64-bit MATLAB and win32 for 32-bit MATLAB.
There are a handful of known issues with running 32-bit MATLAB on 64-bit Windows: MATLAB Parallel Server may fail when both 32-bit MATLAB and 64-bit MATLAB are installed on the same computer. Real-Time Windows Target will not run. Data Acquisition Toolbox cannot connect to parallel ports.
Compiling can accelerate your code by a factor 2, with some luck. Exploiting the underlying maths and improving the MATLAB code can give you a fctor of 100. You find some examples in the forum with 200 and 1000 times faster code in pure Matlab.
It is possible, but it's extremely messy: the whole mbuild/deploytool system is a piece of cr*p in my opinion. First problem with deploytool.bat is that, although having a '-win32' option, that has no effect whatsoever when deploytool is not invoked from the 32bit install directory. Second problem is that the mbuild options are shared for 32 and 64 bit versions so they have to be specified manually as else the wrong compiler options are used.
Here are some things I did to compile both 32bit and 64bit from a 64bit windows machine with VS2010 installed.
<param.c.cpp.options.file>
to the prj under the 'configuration` section (see below)options file config in prj:
<deployment-project>
<configuration ....>
....
<param.c.cpp.options.file>${MATLAB_ROOT}\bin\win32\mbuildopts\msvc100compp.bat</param.c.cpp.options.file>
....
Note that output dir etc will be the same for the 32bit and 64bit versions. In practice, if you have to do this for multiple projects this becomes totally unmanagable. So I have an msbuild script to make life easier: basically in the prj file I replace everything platform dependent (output dir, matlab root dir, options file location) by macros, then let msbuild copy the prj and do a regex find/replace of the macros with values depending on platform. This allows using the same prj for both platforms.
Update
After a few major changes to our projects we found that eventually the hassle of dealing with the matlab prj files was not worth it. Instead, we greatly simplified everything by invoking mcc
directly and feed it with all files belonging to a project. Here is the relevant msbuild code; some error checking skipped for clarity:
<Target Name="BuildMatlabProject">
<PropertyGroup Condition="$(MlPlatform)=='x86'">
<MlMatlabBinDir>$(MlMatlabx86Dir)\bin\win32</MlMatlabBinDir>
</PropertyGroup>
<PropertyGroup Condition="$(MlPlatform)=='x64'">
<MlMatlabBinDir>$(MlMatlabx64Dir)\bin\win64</MlMatlabBinDir>
</PropertyGroup>
<ItemGroup>
<MlMFiles Include="$(MlMatlabProjDir)\*.m"/>
<MlMResources Include="$([System.IO.Directory]::GetDirectories("$(MlMatlabSrcDir)"))"/>
</ItemGroup>
<PropertyGroup>
<MlMresourcseString Condition="@(MlMResources)!=''"> -a @(MlMResources, ' -a ')</MlMresourcseString>
</PropertyGroup>
<RemoveDir Directories="$(MlOutDir)" ContinueOnError="true"/>
<MakeDir Directories="$(MlOutDir)"/>
<Exec Command="$(MlMatlabBinDir)\mcc -W cpplib:$(MlOutputName)_$(MlPlatform)
-T link:lib -d $(MlOutDir) -f $(MlMatlabBinDir)\mbuildopts\msvc100compp.bat
-w enable:specified_file_mismatch -w enable:repeated_file -w enable:switch_ignored
-w enable:missing_lib_sentinel -w enable:demo_license -v
@(MlMFiles, ' ') $(MlMresourcseString)"/>
</Target>
It needs these properties:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With