2011-01-19 156 views
1

我想在Windows下使用QT(http://www.mathworks.com/help/techdoc/matlab_external/f39876.html#bsfvqhp-1)中的Matlab C API來打開一個.mat文件。在我的.pro文件中,我包含了 INCLUDEPATH += "C:\Program Files\MATLAB\R2010b\extern\include" ,它工作正常(代碼編譯)。但是,當試圖鏈接libmat.lib文件(我已閱讀.dll文件不能直接鏈接)時,應用程序在執行時崩潰。給出的錯誤[file].exe exited with code -1073741515將Matlab共享庫鏈接到Qt(Windows)

我既不是QT也不是Windows專家,但對於這個項目我不得不同時使用這兩個(我猜這會更容易解決這個在GNU/Linux),所以任何幫助將不勝感激。使用Windows XP,帶有Qt Creator 2.0.1的QT 4.7.0和Matlab R2010b。

從編譯器只是在情況下,它是有用的最後輸出:

g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug/MainUI.exe debug/main.o debug/maingui.o debug/matparser.o debug/matutils.o debug/moc_maingui.o -L'c:/Qt/2010.05/qt/lib' -lmingw32 -lqtmaind "-LC:\Program Files\MATLAB\R2010b\extern\lib\win32\microsoft" -llibmat -lQtGuid4 -lQtCored4

+0

你使用哪個編譯器,你知道哪個編譯器被用來構建Matlab庫嗎?另外,當您說「讀取了無法直接鏈接的.dll文件」時,您是否可以擴展自己的意思? – Troubadour 2011-01-19 11:53:55

+0

嗨。我不確定QT在Windows中使用哪種編譯器(因爲構建系統是mingw32-make,我猜是win32-g ++),我不知道用於構建Matlab庫的編譯器。當我說DLL文件不能直接鏈接時,我的意思是應該在配置文件(.pro)中使用.lib文件。 – ierax 2011-01-19 12:08:54

回答

2

我剛剛測試建立一個簡單的C程序,使用MAT-File Interface Library沒有問題。示例文件位於:matlabroot/examples/eng_mat/matcreat.c。我正在使用Windows XP 32位機器上的MinGW進行編譯。這裏是我使用的Makefile:

# root directory of MATLAB installation 
MATLABROOT="/c/Program Files/MATLAB/R2010b" 

.PHONY : all clean run 

all: matcreat 

matcreat: 
    gcc ${MATLABROOT}/extern/examples/eng_mat/matcreat.c -o matcreat \ 
     -I${MATLABROOT}/extern/include \ 
     -L${MATLABROOT}/extern/lib/win32/microsoft -llibmat -llibmx 

clean: 
    rm -rf matcreat *.exe *.mat 

run: 
    # UNIX uses LD_LIBRARY_PATH to find libs at runtime, Windows/MinGW uses PATH 
    @PATH=${MATLABROOT}/bin/win32:"${PATH}" ./matcreat