フィルターのクリア

MatLab C++ Shared Dll library initialization problem

23 ビュー (過去 30 日間)
cyvz
cyvz 2016 年 5 月 31 日
コメント済み: yuanjie li 2021 年 3 月 21 日
I am using Matlab 2013a and Visual Studio 2013. I am trying to use MatLab compiled dll from a C++ console application. My simple Matlab test dll and console application is compiled for 64bit machines (I made sure they are 64bit via dumpbin). I also have correct version of MCR installed on my machine (even if it's not necessary).
I setup my compiler using "mbuild -setup" command.
I compile my .m file using this command line: "mcc -v -W cpplib:mylib -T link:lib myFunc" successfully.
In my console application, I include these libraries: mylib.lib, mclmcrrt.lib, mclmcr.lib, libmx.lib, libmat.lib and use the libraries in this path "C:\Program Files\MATLAB\R2013a\extern\lib\win64\microsoft"
When I debug my program, it successfully initializes MCR using this call: "mclInitializeApplication(NULL, 0)" but when I call "mylibInitialize()" in order to initialize my library, program crashes. It doesn't even throw an axception therefore I cannot handle it using try/catch block. It gives unhandled exception and access vialoation error message.
These are sample debug output messages I got;
First-chance exception at 0x00007FFA22761F08 in MatlabTest.exe: Microsoft C++ exception: xercesc_2_7::NoSuchElementException at memory location 0x000000E263EF4E48.
First-chance exception at 0x00007FFA22761F08 in MatlabTest.exe: Microsoft C++ exception: xercesc_2_7::SchemaDateTimeException at memory location 0x000000E263EF4EB8.
First-chance exception at 0x00007FFA22761F08 in MatlabTest.exe: Microsoft C++ exception: xsd_binder::MalformedDocumentError at memory location 0x000000E263EF4E40.
First-chance exception at 0x00007FFA22761F08 in MatlabTest.exe: Microsoft C++ exception: xercesc_2_7::NoSuchElementException at memory location 0x000000E263EF4E48.
First-chance exception at 0x00007FFA22761F08 in MatlabTest.exe: Microsoft C++ exception: boost::thread_interrupted at memory location 0x000000E2643FF630.
First-chance exception at 0x00007FFA22761F08 in MatlabTest.exe: Microsoft C++ exception: xsd_binder::MalformedDocumentError at memory location 0x000000E263EFA640.
First-chance exception at 0x00007FFA22761F08 in MatlabTest.exe: Microsoft C++ exception: boost::thread_interrupted at memory location 0x000000E2642FFCD0.
First-chance exception at 0x00007FFA22761F08 in MatlabTest.exe: Microsoft C++ exception: std::runtime_error at memory location 0x000000E264EFF530.
First-chance exception at 0x00007FFA22761F08 in MatlabTest.exe: Microsoft C++ exception: CryptoPP::AES_PHM_Decryption::InvalidCiphertextOrKey at memory location 0x000000E264EFB0F0.
First-chance exception at 0x00007FFA22761F08 in MatlabTest.exe: Microsoft C++ exception: tfFailedException at memory location 0x000000E264EF4C10.
First-chance exception at 0x00007FFA22761F08 in MatlabTest.exe: Microsoft C++ exception: varflowFailedException at memory location 0x000000E264EF9410. The thread 0x3550 has exited with code 0 (0x0). 'MatlabTest.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2013a\bin\win64\hgbuiltins.dll'. Cannot find or open the PDB file. First-chance exception at 0x0000000000B46E60 (m_interpreter.dll) in MatlabTest.exe: 0xC0000005: Access violation reading location 0x0000000064EF3B90. Unhandled exception at 0x0000000000B46E60 (m_interpreter.dll) in MatlabTest.exe: 0xC0000005: Access violation reading location 0x0000000064EF3B90.
The program '[12952] MatlabTest.exe' has exited with code 0 (0x0).
I installed MCR to another machine and tried to run this console application. I got the same result.
I tried Loren's Vigenere example too,
It didn't work either.
I couldn't find any helpful answer on Matlab community or stackoverflow.
Do you have any idea why this is happening?
Thanks

採用された回答

cyvz
cyvz 2016 年 6 月 15 日
It seems problem is MATLAB and Visual Studio version mismatch. If I use MatLab 2016a with Visual Studio 2013, there is no problem and everything works perfectly.
  3 件のコメント
Markus Schiefele
Markus Schiefele 2017 年 5 月 30 日
Same thing with Matlab 2017a and VisualStudio 2017
money
money 2019 年 7 月 11 日
Do you solve the problem ?

サインインしてコメントする。

その他の回答 (3 件)

Horst Steuer
Horst Steuer 2017 年 11 月 20 日
Had the same issue with MATLAB 2015b, 2016a, 2017b, Visual Studio 2015 and 2017. The program either crashed on "mylibInitialize()" or returned with an empty error message. Turned out that the program actually worked outside of Visual Studio, i.e. starting from command line. Solved it by setting Debugger Type to Managed Only in Visual Studio (Properties of Project -> Configuration Properties -> Debugging -> Debugger Type).
  5 件のコメント
Jevy Lee
Jevy Lee 2019 年 7 月 25 日
Thank you very much! Your approach can solve this problem. My mabtlab ver is 2017b, and vs is 2017.
yuanjie li
yuanjie li 2021 年 3 月 21 日
my ver is 2020b and vs2019, it works, thanks a lot

サインインしてコメントする。


Anatoly Khamukhin
Anatoly Khamukhin 2018 年 1 月 25 日
編集済み: Anatoly Khamukhin 2018 年 1 月 25 日
Problem is in usage of java in MATLAB.
Call
const char *args[] = {"-nojvm"};
const int count = sizeof(args) / sizeof(args[0]);
mclInitializeApplication(args, count))
instead of
mclInitializeApplication(NULL,0)
It solved the same issue for me.
  2 件のコメント
TripleSSSS
TripleSSSS 2018 年 9 月 17 日
It also solved my problem
Andreas Schwarzinger
Andreas Schwarzinger 2021 年 1 月 28 日
Yes. This worked for me as well. Thank you.

サインインしてコメントする。


kishore
kishore 2017 年 8 月 21 日
could you please provide the compatibility version for MATLAB R2016b with visual studio version.
same issue with MATLAB R2016b with visual studio 2013.
  1 件のコメント
Jun Xu
Jun Xu 2020 年 3 月 8 日
https://www.mathworks.com/support/requirements/previous-releases.html

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeC Shared Library Integration についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by