Matlab compiled dll from m-file not linking in c/c++ application

11 vues (au cours des 30 derniers jours)
KME
KME le 25 Mai 2012
I've narrowed the issue to the m-file which I compiled to a dll is not linking at run time. Here are some details:
1. The compiler chose at the Matlab R2011b-32bit commandline was Lcc-win32 C 2.4.1; however, the corresponding h and c files generated with the dll and lib have metadata stating that this is a MATLAB Compiler: 4.16 (R2011b). Looking through the header file, I notice LCC compiler switches. The reason I bring this up is that the literature states the the MCR and the Matlab compiler have to coordinate. In my case the MCR is 7.16 and the compiler should be 4.16.
2. Once this m-file based dll is built, I place it in the working directory and run the program. The program immediately crashes; the call stack indicates that the main function was not reached.
3. The debugger points to the line in gc_support.c:
#else /* defined (_WIN64) */
cookie = systime.ft_struct.dwLowDateTime;
cookie ^= systime.ft_struct.dwHighDateTime;
#endif /* defined (_WIN64) */
So my thoughts on this is that the Matlab compiler is not the correct one? Or, Microsoft VC 2010 is not set up correctly for linking in this m-file based dll?
Here is my general setup for VC 2110 project; hopefully this is helpful:
1. System path has MCR directory before Matlab.
2. Statically link in mclmcrrt.lib, and libut.lib from root\R2011b\extern\lib\win32\microsoft\ and LinearFitModelFnLib.lib (created from m-file) located in the working directory.
3. LinearFitModelFnLib.dll (created from m-file) located in working directory
4. All programs are 32 bit.
I hope this helps; please let me know if you need any more information.

Réponse acceptée

Walter Roberson
Walter Roberson le 25 Mai 2012
As I indicated in your earlier thread, that metadata is being generated by MATLAB Compiler 4.16 as documentation that the .c and .h file were generated by that version. The comments about 4.16 have nothing to do with which compiler you use to compile the generated wrapper functions.
However, I would be concerned about using VC 2010 to link LCC generated code. Mixing manufacturers can be a problem. Easier to eliminate this problem by using VC 2010 as the compiler and linker.
I am uncertain why _WIN64 would be defined for a 32 bit compile; that does not look right to me.
  3 commentaires
Titus Edelhofer
Titus Edelhofer le 25 Mai 2012
Hi,
1. No: let MATLAB Compiler generate a .dll, you should not change this. A remark: MATLAB Compiler is not a C compiler, it calls the C Compiler. MATLAB Compiler can be seen as a tool converting the MATLAB Code to C code which then is compiled by the C compiler (VS/lcc). It is not really converting to C code but the picture fits here.
2. As I wrote, the MATLAB compiler generates the C code and calls the C compilere to generate a DLL. Use VS as a C compiler by using "mbuild -setup".
KME
KME le 25 Mai 2012
Thanks! That solved the issue. Using mbuild with the VC compiler created the dll that functioned. I guess I thought since this was a simple c dll, the brand of compiler wouldn't be an issue. But, MS is tricky with other tools.

Connectez-vous pour commenter.

Plus de réponses (1)

Titus Edelhofer
Titus Edelhofer le 25 Mai 2012
Hi,
just a comment regarding point 1): entering the following in R2011b to confirm:
[x,y]=mcrversion
x =
7
y =
16
So indeed, MCR 7.16 is the correct one. This corresponds to MATLAB Compiler 4.16:
ver('Compiler')
...
MATLAB Compiler Version 4.16 (R2011b)
The MATLAB Compiler version should not be mixed up with the C compiler version (lcc). But I would suggest the same as Walter: use VC for the compiler, if you compile your application with VC as well ...
You might want to try to use mbuild to compile your application instead of visual studio, you will see (using verbose mode) what libraries are actually linked and how ...
Titus

Catégories

En savoir plus sur C Shared Library Integration dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by