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

13 次查看(过去 30 天)
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 个评论
Jan
Jan 2018-5-16
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 2018-5-16
编辑:AM 2018-5-16
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...

请先登录,再进行评论。

回答(4 个)

Rik
Rik 2018-5-16
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 个评论
AM
AM 2018-6-2
As said above, I re-released and re-build the .exe file without some links to Intel MKL. That worked for me...

请先登录,再进行评论。


Daniel Benitez
Daniel Benitez 2018-9-14
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 2019-11-26
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 2020-2-7
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

类别

Help CenterFile Exchange 中查找有关 MATLAB Compiler 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by