将 Matlab 共享库链接到 Qt (Windows)
我想在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 includedINCLUDEPATH += "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) usingLIBS += -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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我刚刚测试了构建一个简单的 C 程序,该程序使用 MAT 文件接口库 没有任何问题。示例文件位于:
matlabroot/examples/ eng_mat/matcreat.c
。我正在 Windows XP 32 位计算机上使用 MinGW 进行编译。这是我使用的 Makefile: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:我怀疑 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.