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

13 visualizzazioni (ultimi 30 giorni)
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
system('File_Name.exe')
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 :)
Best,
  2 Commenti
Jan
Jan il 16 Mag 2018
My first guess is that the current folder is not, what you expect it to be and that you run another "File_Name.exe" as you think you do. What exactly does "gives some number as output (-1.0737e+09)" mean? Where is this number written to?
AM
AM il 16 Mag 2018
Modificato: AM il 16 Mag 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
system('cmd')
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...

Accedi per commentare.

Risposte (4)

Rik
Rik il 16 Mag 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.
  3 Commenti
AM
AM il 2 Giu 2018
As said above, I re-released and re-build the .exe file without some links to Intel MKL. That worked for me...

Accedi per commentare.


Daniel Benitez
Daniel Benitez il 14 Set 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 il 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 il 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 https://software.intel.com/en-us/forums/intel-fortran-compiler/topic/759093 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! :)
Josh

Categorie

Scopri di più su MATLAB Compiler in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by