当使用fopen文件时,matlab崩溃时没有转储文件 [英] matlab crashes without dump file when using fopen for file

查看:220
本文介绍了当使用fopen文件时,matlab崩溃时没有转储文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用gnumex与mingw编译Windows操作系统中matlab中的mex文件。我无法使用fopen命令打开文件。以下是我正在使用的代码。

  #include  
#includemex.h
void mexFunction(int nlhs,mxArray * plhs [],int nrhs,const mxArray * prhs [])
{
FILE * fp =空值;
fp = fopen(test.txt,w +);
}

程序编译成功,但是当我尝试运行编译mexw64文件时,matlab简单地关闭而不生成任何转储文件。



请注意,我可以运行简单的Hello World程序,并使用其他mex程序传递和接收参数。



Update1:​​添加flips(fp)不会改变行为。



Update2:我无法使用 http://www.mathworks.com/help/matlab /matlab_external/debugging-on-microsoft-windows-platforms.html ,因为我正在使用mingw以及windows中的gnumex设置编译

更新3:输出

  mex -v file.cpp 

这是mex,版权所有1984-2007 The MathWorks,Inc 。


- >在C:\Users\achaudhary\AppData\Roaming\MathWorks\MATLAB\R2009b
中找到默认选项文件名------------------ ----------------------------------------------
- >选项文件= C:\ Users \\ Application \ Application \ Roaming \ MathWorks \\
- > COMPILER = gcc
- >编译器标志:
COMPFLAGS = -c -DMATLAB_MEX_FILE -x c ++
OPTIMFLAGS = -O3
DEBUGFLAGS = -g
参数=
名称开关= -o
- >预链接命令=
- > LINKER = C:\PROGRA〜1 \MATLAB\R2009b\sys\perl\win32\bin\perl.exe E:\MATLAB〜1 \linkmex.pl
- > ; Link指令:
LINKFLAGS = -mwindows -LC:\Users\ACHAUD〜1\AppData\Roaming\MATHWO〜1\MATLAB\R2009b\gnumex GM_ISCPP -mwindows
LINKDEBUGFLAGS = -g -Wl, - image-base,0x28000000\
LINKFLAGSPOST =
命名指令= -o file.mexw64
文件链接指令=
Lib。 link指令=
Rsp文件指示符=
- >资源编译器= C:\PROGRA〜1 \MATLAB\R2009b\sys\perl\win32\bin\perl.exe E:\MATLAB〜1 \rccompile.pl --unix -o mexversion.res
- >资源链接器=
------------------------------------------- ---------------------


- > gcc -c -DMATLAB_MEX_FILE -x c ++ -oC:\USERS\ACHAUD_1\APPDATA\LOCAL\TEMP\MEX_FZ_1\file.obj -IC:\\PROGRA_1\MATLAB\\ \\ R2009b \ extern \ include -IC:\ PROGRAM〜1 \MATLAB\R2009b\simulink\include -O3 -DMX_COMPAT_32 file.cpp


- > ; C:\PROGRA〜1 \MATLAB\R2009b\sys\perl\win32\bin\perl.exe E:\MATLAB〜1 \linkmex.pl -o file.mexw64 -mwindows - LC:\ Users \ACHAUD〜1 \AppData\Roaming\MATHWO~1\MATLAB\R2009b\gnumex GM_ISCPP -mwindows -s C:\ USER \\\\\\\\\\\\ LOCAL \ TEMP \MEX_FZ〜1 \file.obj

链接命令:g ++ -shared C:\ Users \\\\\\\\'' \\MATLAB \R2009b\gnumex\mex.def -o file.mexw64 -mwindows -LC:\ Users \ACHAUD〜1\AppData\Roaming\MATHWO〜1\MATLAB\R2009b\ gnumex -mwindows -s C:\USERS\ACHAUD~1\APPDATA\LOCAL\TEMP\MEX_FZ~1\file.obj -llibmx -llibmex -llibmat

编辑
我现在可以使用minGw,但问题仍然存在于cygwin中。使用cygwin的解决方案仍然没有找到。

解决方案

看着windgb调试器,发现mex文件正在使用库来自早期安装的cygwin64。为了使以前的安装工作,我必须手动删除由gnumex生成的mexopts.bat中的-mno-cygwin标志,因为它与安装的gcc版本不兼容。不知何故,除FILE之外的所有东西都打开了工作。



因此,新安装了mingw64和附加的环境路径。然后使用mingw64重新安装gnumex,现在一切正常,minGw工作正常。



注意:使用cygwin时问题仍然存在。


I am using gnumex with mingw for compiling mex files in matlab in Windows OS. I am not able to use fopen command to open files. Following is the code which I am using.

#include <stdio.h>
#include "mex.h"
void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
{
    FILE  *fp=NULL;
    fp = fopen("test.txt", "w+");
}

The program compiles succesfully but when I try to run the compile mexw64 file, matlab simply closes down without generating any dump file.

Note that I am able to run simple Hello world program and passing and receiving arguments using other mex programs.

Update1: adding flcose(fp) does not change behaviour.

Update2: I cannot debug using http://www.mathworks.com/help/matlab/matlab_external/debugging-on-microsoft-windows-platforms.html as I am compiling using mingw along with gnumex setup in windows

Update 3: Output of

mex -v file.cpp

 This is mex, Copyright 1984-2007 The MathWorks, Inc. 


-> Default options filename found in C:\Users\achaudhary\AppData\Roaming\MathWorks\MATLAB\R2009b 
---------------------------------------------------------------- 
->    Options file           = C:\Users\achaudhary\AppData\Roaming\MathWorks\MATLAB\R2009b\mexopts.bat 
      MATLAB                 = C:\PROGRA~1\MATLAB\R2009b 
->    COMPILER               = gcc 
->    Compiler flags: 
         COMPFLAGS           = -c -DMATLAB_MEX_FILE -x c++ 
         OPTIMFLAGS          = -O3 
         DEBUGFLAGS          = -g 
         arguments           =  
         Name switch         = -o 
->    Pre-linking commands   =  
->    LINKER                 = C:\PROGRA~1\MATLAB\R2009b\sys\perl\win32\bin\perl.exe E:\MATLAB~1\linkmex.pl 
->    Link directives: 
         LINKFLAGS           =   -mwindows -LC:\Users\ACHAUD~1\AppData\Roaming\MATHWO~1\MATLAB\R2009b\gnumex GM_ISCPP   -mwindows 
         LINKDEBUGFLAGS      = -g  -Wl,--image-base,0x28000000\n 
         LINKFLAGSPOST       =  
         Name directive      = -o file.mexw64 
         File link directive =  
         Lib. link directive =  
         Rsp file indicator  =  
->    Resource Compiler      = C:\PROGRA~1\MATLAB\R2009b\sys\perl\win32\bin\perl.exe E:\MATLAB~1\rccompile.pl --unix -o mexversion.res 
->    Resource Linker        =  
---------------------------------------------------------------- 


--> gcc  -c -DMATLAB_MEX_FILE -x c++ -oC:\USERS\ACHAUD~1\APPDATA\LOCAL\TEMP\MEX_FZ~1\file.obj -IC:\PROGRA~1\MATLAB\R2009b\extern\include -IC:\PROGRA~1\MATLAB\R2009b\simulink\include -O3 -DMX_COMPAT_32 file.cpp 


--> C:\PROGRA~1\MATLAB\R2009b\sys\perl\win32\bin\perl.exe E:\MATLAB~1\linkmex.pl -o file.mexw64   -mwindows -LC:\Users\ACHAUD~1\AppData\Roaming\MATHWO~1\MATLAB\R2009b\gnumex GM_ISCPP   -mwindows -s  C:\USERS\ACHAUD~1\APPDATA\LOCAL\TEMP\MEX_FZ~1\file.obj   

link command: g++ -shared C:\Users\ACHAUD~1\AppData\Roaming\MATHWO~1\MATLAB\R2009b\gnumex\mex.def -o file.mexw64 -mwindows -LC:\Users\ACHAUD~1\AppData\Roaming\MATHWO~1\MATLAB\R2009b\gnumex  -mwindows -s C:\USERS\ACHAUD~1\APPDATA\LOCAL\TEMP\MEX_FZ~1\file.obj -llibmx -llibmex -llibmat 

EDIT I am able to work with minGw now but the problem still persists with cygwin. The solution to working with cygwin still not found.

解决方案

Looked at the windgb debugger and found out that mex file was using libraries from cygwin64 from earlier installation as well. To make the previous installation work, I had to remove -mno-cygwin flag from the mexopts.bat generated by gnumex manually as it was incompatible with the installed gcc version. Somehow, everything apart from FILE open worked.

So did a fresh install of mingw64 and appended environment paths accordingly. Then reinstalled gnumex using mingw64 and now everything works fine with minGw.

Note: The problem still remains when working with cygwin.

这篇关于当使用fopen文件时,matlab崩溃时没有转储文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆