将 Matlab 共享库链接到 Qt (Windows)

发布于 2024-10-12 22:33:38 字数 984 浏览 1 评论 0原文

我想在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 文件无法直接链接)使用 LIBS += -L"C:\Program Files\MATLAB\R2010b\extern\lib\win32\microsoft" -llibmat 应用程序在执行时崩溃。给出的错误说 [file].exe exited with code -1073741515

我既不是 QT 也不是 Windows 专家,但对于这个项目,我被迫使用两者(我想修复起来会更容易这在 GNU/Linux 中)所以任何帮助将不胜感激。使用 Windows XP、QT 版本 4.7.0 和 Qt Creator 2.0.1 以及 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

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\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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

攒一口袋星星 2024-10-19 22:33:38

我刚刚测试了构建一个简单的 C 程序,该程序使用 MAT 文件接口库 没有任何问题。示例文件位于: 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

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
放我走吧 2024-10-19 22:33:38

我怀疑 Matlab 库将使用 MSVC 进行编译,并且既然你说你正在使用 MingW 编译你自己的代码,我想这两者是不兼容的。

请参阅有关混合编译器的 MingW 页面了解更多信息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文