2012-11-26 2 views
7

Ich habe ein Laufzeitproblem mit meinem Matlab c/C++ freigegeben lib. Die Bibliothek exportiert und die Anwendung ist kompiliert und ordnungsgemäß verknüpft. Zur Laufzeit scheint das Skript jedoch viele Fehler zu enthalten. Es wird kein Fehler im Konsolenfenster (Anzeige der Matlab-Ausgabe) meiner Anwendung angezeigt. Aber der Debugger zeigt eine Menge von nicht abgefangenen Ausnahmen auf dem Lauf. Das Skript scheint jedoch zu durchlaufen und die Anwendung wird ordnungsgemäß beendet.Matlab Shared C/C++ - Bibliothek in VS10/12 wirft viele Ausnahmen

einige Dinge wissen:

  • Aufbauend auf Win8 Pro x64
  • Visual Studio 2012 (Projekteinstellungen sind VS 2010, die korrekt installiert ist)
  • Matlab R2012b (32Bit) (64Bit-Version ist auch installiert, aber hier nicht verwendet, soweit ich weiß)
  • MCR R2012b win32/64
  • Compiler in Matlab Compiler installiert und verwendet wird, ist die VS2010 ein (Kompilieren mit GUI-Compiler)

Nun, hier ist die m-Datei i zu einem gemeinsamen lib am Export:

% Create video input object. 
vid = videoinput('winvideo', 1, 'YUY2_320x240') 

% Set video input object properties for this application. 
set(vid,'TriggerRepeat',Inf); 
vid.FrameGrabInterval = 3; 

% Set value of a video source object property. 
vid_src = getselectedsource(vid); 
set(vid_src,'Tag','motion detection setup'); 
set(vid,'ReturnedColorSpace','rgb'); 

% Create a figure window. 
figure; 
% wiener filter neighbourhood 
wienerFilter = [5 5]; 
% Start acquiring frames. 
start(vid) 

% Calculate difference image and display it. 
while(vid.FramesAcquired<=200) % Stop after 200 frames 
    data = getdata(vid,2); 

    first_img = wiener2(rgb2gray(data(:,:,:,1)), wienerFilter); 
    second_img = wiener2(rgb2gray(data(:,:,:,2)), wienerFilter); 

    bw_img = im2bw(first_img); 

    diff_im = imabsdiff(first_img,second_img); 

    subplot(1,3,1), imshow(first_img); 
    subplot(1,3,2), imshow(second_img); 
    subplot(1,3,3), imshow(diff_im); 

end 

stop(vid) 

delete(vid) 
close(gcf) 

Wenn Sie eine Webcam auf Ihrem Computer das Skript ausgeführt werden, ohne Fehler!

Nun ist die wichtigste C++ Datei:

#include "stdafx.h" 
#include "MatlabCompilerSample.h" 

#pragma comment(lib, "MatlabCompilerSample.lib") 

int _tmain(int argc, _TCHAR* argv[]) 
{ 
    /* Call the MCR and library initialization functions */ 
    if(!mclInitializeApplication(NULL,0)) 
    { 
     const char* message = mclGetLastErrorMessage(); 
     printf_s(message); 
     fprintf(stderr, "Could not initialize the application.\n"); 
     exit(1); 
    } 

    if (!MatlabCompilerSampleInitialize()) 
    { 
     fprintf(stderr,"Could not initialize the library.\n"); 
     exit(1); 
    } 

    /* Call the implementation function */ 
    WebcamSample(); 

    /* Call the library termination function */ 
    MatlabCompilerSampleTerminate(); 

    mclTerminateApplication(); 
    return 0; 
} 

Sieht bis jetzt gut? Nach dem Laden einiger Dlls beginnt das Durcheinander. Blick auf die Ausnahmen und Mist geworfen:

'MatlabCompilerCPPExample.exe' (Win32): Loaded 'C:\Windows\WinSxS\x86_microsoft.vc90.mfcloc_1fc8b3b9a1e18e3b_9.0.30729.6161_none_49768ef57548175e\MFC90DEU.DLL'. Module was built without symbols. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: std::runtime_error at memory location 0x003DF4A0. 
SetThrowSegvLongjmpSEHFilter(): filter function installed 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: xsd_binder::MalformedDocumentError at memory location 0x003D6210. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: xsd_binder::MalformedDocumentError at memory location 0x003D5A4C. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: xsd_binder::MalformedDocumentError at memory location 0x003D6210. 

Nun, das ist auf eine Zeit lang geht und dann:

'MatlabCompilerCPPExample.exe' (Win32): Loaded 'C:\Windows\SysWOW64\profapi.dll'. Cannot find or open the PDB file. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: boost::thread_interrupted at memory location 0x060EFD98. 
The thread 0x2478 has exited with code 0 (0x0). 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: xsd_binder::MalformedDocumentError at memory location 0x003DE000. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: xsd_binder::MalformedDocumentError at memory location 0x003DD83C. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: xsd_binder::MalformedDocumentError at memory location 0x003DE000. 

Das ist noch nicht alles ...

First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: xsd_binder::MalformedDocumentError at memory location 0x003DD0B4. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: xsd_binder::MalformedDocumentError at memory location 0x003DDEA0. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: boost::thread_interrupted at memory location 0x061EF980. 
The thread 0x282c has exited with code 0 (0x0). 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: xsd_binder::MalformedDocumentError at memory location 0x003DE328. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: xsd_binder::MalformedDocumentError at memory location 0x003DDB64. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: xsd_binder::MalformedDocumentError at memory location 0x003DE328. 

...

First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: xsd_binder::MalformedDocumentError at memory location 0x003DE1C8. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: boost::thread_interrupted at memory location 0x061EFC14. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: boost::thread_interrupted at memory location 0x060EFDEC. 
The thread 0x32a4 has exited with code 0 (0x0). 
The thread 0x350c has exited with code 0 (0x0). 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: boost::thread_interrupted at memory location 0x060EFC1C. 
The thread 0xfd8 has exited with code 0 (0x0). 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: boost::thread_interrupted at memory location 0x05FEFC7C. 
The thread 0x2144 has exited with code 0 (0x0). 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'N:\Programme\MATLAB\2012b (32Bit)\sys\java\jre\win32\jre\bin\client\jvm.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winmm.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr71.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winmmbase.dll'. Cannot find or open the PDB file. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: std::runtime_error at memory location 0x0771F404. 
SetThrowSegvLongjmpSEHFilter(): filter function installed 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'C:\Windows\SysWOW64\NapiNSP.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'C:\Windows\SysWOW64\pnrpnsp.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'C:\Windows\SysWOW64\nlaapi.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'C:\Windows\SysWOW64\mswsock.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dnsapi.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winrnr.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'C:\Program Files (x86)\Common Files\Microsoft Shared\Ink\tiptsf.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'N:\Programme\MATLAB\2012b (32Bit)\sys\java\jre\win32\jre\bin\verify.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'N:\Programme\MATLAB\2012b (32Bit)\sys\java\jre\win32\jre\bin\java.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'N:\Programme\MATLAB\2012b (32Bit)\sys\java\jre\win32\jre\bin\hpi.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'N:\Programme\MATLAB\2012b (32Bit)\sys\java\jre\win32\jre\bin\zip.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'N:\Programme\MATLAB\2012b (32Bit)\sys\java\jre\win32\jre\bin\fontmanager.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'N:\Programme\MATLAB\2012b (32Bit)\sys\java\jre\win32\jre\bin\awt.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'C:\Windows\SysWOW64\apphelp.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'N:\Programme\MATLAB\2012b (32Bit)\bin\win32\nativejmi.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'N:\Programme\MATLAB\2012b (32Bit)\bin\win32\nativeservices.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'N:\Programme\MATLAB\2012b (32Bit)\bin\win32\nativejava.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'N:\Programme\MATLAB\2012b (32Bit)\sys\java\jre\win32\jre\bin\net.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'N:\Programme\MATLAB\2012b (32Bit)\sys\java\jre\win32\jre\bin\nio.dll'. Cannot find or open the PDB file. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: std::runtime_error at memory location 0x0771F284. 
SetThrowSegvLongjmpSEHFilter(): filter function installed 
First-chance exception at 0x76AB4B32 (KernelBase.dll) in MatlabCompilerCPPExample.exe: 0x000006BA: Der RPC-Server ist nicht verfügbar. 
The thread 0x37b0 has exited with code 0 (0x0). 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: CryptoPP::AES_PHM_Decryption::InvalidCiphertextOrKey at memory location 0x0771C1B8. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: CryptoPP::AES_PHM_Decryption::InvalidCiphertextOrKey at memory location 0x0771C988. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: tfFailedException at memory location 0x077189E7. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: tfFailedException at memory location 0x0771B82C. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: tfFailedException at memory location 0x07717E57. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: tfFailedException at memory location 0x0771ACA0. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'N:\Programme\MATLAB\2012b (32Bit)\bin\win32\libmwbuiltins.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'N:\Programme\MATLAB\2012b (32Bit)\bin\win32\mlint.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'C:\Windows\SysWOW64\version.dll'. Cannot find or open the PDB file. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: tfFailedException at memory location 0x07717E57. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: tfFailedException at memory location 0x0771ACA0. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'N:\Programme\MATLAB\2012b (32Bit)\bin\win32\libmwmathelem.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'N:\Programme\MATLAB\2012b (32Bit)\bin\win32\libmwmathxps.dll'. Cannot find or open the PDB file. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: varflowFailedException at memory location 0x0771BCD7. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: varflowFailedException at memory location 0x0771BD82. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'N:\Programme\MATLAB\2012b (32Bit)\bin\win32\hgbuiltins.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'N:\Programme\MATLAB\2012b (32Bit)\bin\win32\nativemvm.dll'. Cannot find or open the PDB file. 
'MatlabCompilerCPPExample.exe' (Win32): Loaded 'N:\Programme\MATLAB\2012b (32Bit)\bin\win32\nativehg.dll'. Cannot find or open the PDB file. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: CryptoPP::AES_PHM_Decryption::InvalidCiphertextOrKey at memory location 0x07716AC0. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: tfFailedException at memory location 0x07714C0F. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: tfFailedException at memory location 0x07717A5C. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: CryptoPP::AES_PHM_Decryption::InvalidCiphertextOrKey at memory location 0x07717628. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: tfFailedException at memory location 0x0771367F. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: tfFailedExceptionNoUCB at memory location 0x077137EC. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: tfFailedException at memory location 0x07715940. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: tfFailedException at memory location 0x077162C7. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: tfFailedException at memory location 0x07719110. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: varflowFailedException at memory location 0x07719773. 
First-chance exception at 0x76AB4B32 in MatlabCompilerCPPExample.exe: Microsoft C++ exception: varflowFailedException at memory location 0x077197EE. 

Die ganze Datei ist 6000 l ines ... Ich poste es wenn nötig! Hier hält es schließlich:

First-chance exception at 0x76AB4B32 (KernelBase.dll) in MatlabCompilerCPPExample.exe: 0xA1A01DB2 (parameters: 0x1FD09FE6, 0x1FD08200, 0x00000000). 
The program '[3324] MatlabCompilerCPPExample.exe' has exited with code 0 (0x0). 

ich für jeden Hinweis freuen würde, Dank im Voraus!

+0

Viele dieser Nachrichten scheinen mit der Tatsache in Zusammenhang zu stehen, dass für die DLL keine Debuggersymbole definiert sind. Es stürzt irgendwo ab, versucht in den Debug-Modus zu wechseln und schlägt fehl. –

+0

Auch. Haben Sie versucht, einfache 'Hallo Welt' Art von Programm zu kompilieren? Läuft Ihre Compiler-Pipeline normalerweise ohne Fehler? Einer meiner Lieblingstakte ist es, Zeilen in das Matlab-Skript einzufügen und hinzuzufügen, um zu sehen, wann genau es fehlschlägt. –

Antwort

2

Dies sind alle Ausnahmen der ersten Chance und bedeutet nicht, dass es ein Problem gibt. Ich habe sie in meinem vorherigen Job oft gesehen und Matlab hat eine Tendenz, eine Menge Ausnahmen zu produzieren, was kein echtes Problem war.

http://blogs.msdn.com/b/davidklinems/archive/2005/07/12/438061.aspx

Gibt es eine erste Chance bedeuten, dass es ein Problem in meinem Code? Erste-Chance-Ausnahmemeldungen bedeuten meistens nicht, dass ein Problem im Code vorliegt.Bei Anwendungen/Komponenten, die Exceptions ordnungsgemäß behandeln, wird der Entwickler durch eine Exception-Nachricht der ersten Chance darüber informiert, dass eine Ausnahmesituation aufgetreten ist und behandelt wurde.

+0

Das eigentliche Problem ist, dass MATLAB tatsächlich ein _lot_ von Ausnahmen sowohl während der Initialisierung als auch während der Ausführung auslöst. Sie werden offensichtlich intern behandelt, aber es scheint mir, dass dies zeigt, dass ihr Programmiermodell die Anti-Muster der Verwendung von Ausnahmen anstelle anderer geeigneterer Flusssteuerungsmethoden und das Schlucken potenziell gültiger Ausnahmen enthält (wenn ich eine MATLAB-basierte Anwendung debugge) Ich werde oft feststellen, dass der Debugger mit der AccessViolation-Ausnahme stoppt, die einen Speicherbereich von fast Null liest. – Mozzis

Verwandte Themen