Running exe file created with C++ from Matlab not working
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Jan
le 16 Mai 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?
Réponses (4)
Rik
le 16 Mai 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 commentaires
Daniel Benitez
le 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.
0 commentaires
Shilpa Nayak
le 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.
0 commentaires
Josh Philipson
le 7 Fév 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
0 commentaires
Voir également
Catégories
En savoir plus sur MATLAB Compiler dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!