开发者

Linking Matlab shared library into Qt (Windows)

开发者 https://www.devze.com 2023-02-05 06:03 出处:网络
I want to use Matlab\'s C API within QT (http://www.mathworks.com/help/techdoc/matlab_external/f39876.html#bsfvqhp-1) under Windows for opening a .mat file. In my .pro file I have included

I want to use Matlab's C API within QT (http://www.mathworks.com/help/techdoc/matlab_external/f39876.html#bsfvqhp-1) under Windows for opening a .mat file. In my .pro file I have included INCLUDEPATH += "C:\Program Files\MATLAB开发者_如何学Python\R2010b\extern\include" which works fine (the code compiles). But when trying to link the libmat.lib file (I have read the .dll files cannot be linked directly) using LIBS += -L"C:\Program Files\MATLAB\R2010b\extern\lib\win32\microsoft" -llibmat the application crashes on execution. The error given says [file].exe exited with code -1073741515

I'm neither a QT nor a Windows expert but for this project I am forced to use both (I guess it would be easier to fix this in GNU/Linux) so any help would be appreciated. Using Windows XP, QT version 4.7.0 with Qt Creator 2.0.1, and Matlab R2010b.

The last output from the compiler just in case it is useful:

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


I just tested building a simple C program that uses the MAT-File Interface Library with no problems. The example file is located in: matlabroot/examples/eng_mat/matcreat.c. I am compiling using MinGW on a Windows XP 32-bit machine. Here is the Makefile I used:

# 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


I suspect that the Matlab library will have been compiled with MSVC and since you say you are compiling your own code with MingW I would imagine the two are incompatible.

Have a look at the MingW page on mixing compilers for more information.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号