简体   繁体   English

Matlab将无法运行我的C ++ .exe文件

[英]Matlab will not run my C++ .exe file

I have program in C++ that runs great but it has different steps in it. 我有运行良好的C ++程序,但其中有不同的步骤。 It opens a file first then does some calculations based on the data it gets from the file. 它首先打开一个文件,然后根据从文件中获取的数据进行一些计算。 Now I'm trying to run it through matlab. 现在,我正在尝试通过matlab运行它。 I tried mex but it got too complicated because I have VS 2010 Express and MATLAB 2007b. 我尝试了mex,但是它变得太复杂了,因为我拥有VS 2010 Express和MATLAB 2007b。 And so mex can never find my c compiler. 因此,mex永远找不到我的c编译器。

I'm now trying to just run it straight from the C++ program executable file. 我现在正尝试直接从C ++程序可执行文件运行它。 Here's how I tried to do it: 这是我尝试执行的操作:

system('C:\path\file.exe')

it would run but the command window freezes and I have to close Matlab every time to get back on track. 它会运行,但命令窗口冻结,我每次必须关闭Matlab才能回到正轨。 Then I tried to double click on the executable file it self. 然后我尝试双击可执行文件本身。 It flashes but I can see it outputs something from my file "file could not be uploaded" which is generated by a part of my program if it cant find the file. 它闪烁,但是我可以看到它从我的文件"file could not be uploaded"输出了一些内容,如果找不到文件,该文件是程序的一部分生成的。

So then I realized it's probably because of that that caused it to not run and crash. 因此,我意识到可能是因为该原因导致它无法运行并崩溃。 So I wrote a sample code to open the file first before the system command open the .exe file. 因此,我写了一个示例代码,在系统命令打开.exe文件之前先打开该文件。 I've done something like fopen('fname','r') , but nothing works. 我已经做了类似fopen('fname','r')事情,但是没有任何效果。 Please note that this file I'm trying to open is a .COF file. 请注意,我尝试打开的文件是.COF文件。

I tried running the .exe file using debug and release modes but nothing happens. 我尝试使用调试和发布模式运行.exe文件,但没有任何反应。 It gives no errors which means it sees the .exe file but the command line doesn't come up and matland command window freezes. 它没有给出任何错误,这意味着它可以看到.exe文件,但命令行不出现并且matland命令窗口冻结。

After running, it's supposed to prompt the user at the command line then take input arguments and output something... 运行后,应该在命令行提示用户,然后接受输入参数并输出一些内容...

Please help.... 请帮忙....

I am guessing that your .COF file is in a different path than what's accessible by your binary. 我猜想您的.COF文件与您的二进制文件无法访问的路径不同。 If you can recompile, try an absolute path name, and test it first without MATLAB. 如果可以重新编译,请尝试使用绝对路径名,并首先在没有MATLAB的情况下对其进行测试。

There are more thorough ways to solve this, like passing the filename to your binary as a command line argument, or to read up what the rules are for the "current directory" when you use system , but perhaps you'd be happy with the quick solution. 有更彻底的方法可以解决此问题,例如将文件名作为命令行参数传递给二进制文件,或者在使用system时读取“当前目录”的规则,但也许您会对快速解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM