MATLAB Answers

Running exe file created with C++ from Matlab not working

23 views (last 30 days)
AM on 16 May 2018
Answered: Josh Philipson on 7 Feb 2020
Dear all,
I have a weird problem with a .exe file I'm trying to run in a Matlab script. Executing the .exe file from either Visual Studio or the Windows command prompt works fine and the exe file creates a csv file as it is supposed to do. However, when I'm running the file from the Matlab command window via
it only gives some number as output (-1.0737e+09) and does not create the csv file. When I double click the exe file in the Folder menu in Matlab it also works as intended. Does anyone know what I am doing wrong? The system('FileName.exe') command works for other dummy programmes I have created so I'm really wondering what has changed.
Your help is much appreciated :)
AM on 16 May 2018
Dear Jan, first, let me thank you for your reply. The output (-1.0737e+09) is written to the command window as some kind of result for the execution. I have double checked the current folder location, so I'm pretty sure this one is set up correctly.
One more thing I just realized is that when I run
and then enter the same command as when I open a Windows console it also does not run the exe file. It kind of seems like the console Matlab opens is different to the console Windows is using. I have checked this in both environments (Windows console and Matlab's system('cmd')); first checking that the folder location is correct via
cd C:\Users\me\Folder_Location
and then running the exe file. In the windows console this works, in the Matlab console it does not...

Sign in to comment.

Answers (4)

Rik on 16 May 2018
And if you try to cd inside the same system call?
system('cd /d C:\Users\me\Folder_Location && File_Name.exe')
The /d enables a cd to a different disk, and the && ensures the second command only runs if the first exits successfully.
AM on 2 Jun 2018
As said above, I re-released and re-build the .exe file without some links to Intel MKL. That worked for me...

Sign in to comment.

Daniel Benitez
Daniel Benitez on 14 Sep 2018
I had the same problem and tried many different things. I solved it just by installing the newest Matlab Version 2018a. With R2017b the exe-file was not working. Perhaps to reinstall the older Version would also solve the problem, since I have updated the Runtime Environment in the meanwhile.

Shilpa Nayak
Shilpa Nayak on 26 Nov 2019
This was the best answer I could find! I had exactly the same problem that's described here and switching to other MATLAB versions weren't a good option (for me). And this solved it.

Josh Philipson
Josh Philipson on 7 Feb 2020
Hi, I think I may have found something potentially helpful.
I had a very similar issue, and just resolved it. In case it's relevant, I was using Intel's Fortran compiler in a Visual Studio project to build a fortran file. The built EXE was trying to load some dll that it couldn't do from within MATLAB, but within native windows cmd window, or double-click it could do it.
The relevant bit was from the magician, "Ian H (blackbelt)", over at who posted this bit:
  • You need to change the runtime library setting for your project within Visual Studio - the default within Visual Studio is to produce an executable that requires the Fortran runtime libraries.
  • Change to a Release configuration, then rIght click on your project in the solution explorer, select Properties, then in the Configuration Properties > Fortran > Libraries page change the Runtime Library option to "Multithreaded". Rebuild your project.
  • (If you use OpenMP within your project, then you will still have a dependency on some of the OpenMP DLL's.)
I sort of backed into this when I tried to run my compiled .exe on another PC that didn't have the same build environment setup, and it barfed on me indicating "libmmdd.dll" was not found. Additionally, I tried system('cmd &') to have Matlab open up a command window..and I found that one compiled version (i.e. via G77) worked, and the one I used Visual Studio for didn't work! (i.e. emulating FORTRAN IV/66 semantics (Sheesh, don't ask!)) .
From there I guess that it couldn't load that library in the MATLAB "system" scaffolding. I am not sure.
Regardless, for me the key was changing the "Runtime Library" option to "Multithreaded", from "Multithreaded dll". As soon as I could do it, the exe was runnable.
Hope this helps someone! :)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!