Using MATLAB API in C++, matOpen crashing program silently

半腔热情 提交于 2021-01-29 21:23:54

问题


my problem is similar to this one but it is rather old and I cannot comment or upvote due to my (beginners) reputation. I am trying to compile the matcreat.cpp file from Matlab 2017b like this (using g++ (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0):

g++ -c -o matcreat.o -I"C:\Program Files\MATLAB\R2017b\extern\include" matcreat.cpp
g++ -o matcreat.exe matcreat.o -L"C:\Program Files\MATLAB\R2017b\extern\lib\win64\mingw64" -llibmat -llibmex -llibmx -llibeng

The program has a main which uses printf right at the beginning (even before the matlab stuff), but nothing is put out and it just terminates. If I comment out all the MATLAB related function calls it works, the first one being pmat = matOpen(file, "w");.

Why is the program just silently crashing and outputting nothing? Why no compiler/linker errors? Any ideas whout be greatly appreciated.


回答1:


After some time trying to work around the internals of the mex building process I gave up on that route. Mathworks is deliberately trying to make it hard to incorporate their features into your own code.

For everyone with the same problems: After some research I found this open source project, which can write MAT files just fine.



来源:https://stackoverflow.com/questions/63507252/using-matlab-api-in-c-matopen-crashing-program-silently

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!