Application Extension .dll from a .c File

I have no MATLAB experience. I inherited a piece of Labview code that uses a Matlab complied .dll
Problem is the .dll had a memory leak that I was able to detect and remove.
Now I have no idea how to recompile the c File to produce the .dll file.
The c file has a comment that I believe relates to how the file must be compiled, see below
/* MATLAB Compiler: 4.3 (R14SP3)
* Arguments: "-B" "macro_default" "link:lib" "reverse_wrapper.m"
*/
The c File is in a folder that has a number of other files including ranging from .dll .m .exports and .m files
Searching the development PC, I see MATLAB Component Runtime version 7.3 is installed.
Please help me with a detailed step by step procedure to get compile my .c file into a .dll do I need to download a compiler and other tools?

13 件のコメント

Walter Roberson
Walter Roberson 2021 年 12 月 11 日
You will need MATLAB Compiler product.
If you were using a much newer release of MATLAB, you would also need MATLAB Compiler SDK.
Unfortunately, the version you are using is so old that a lot of practical knowledge of it has been lost -- it operated quite differently than modern versions. @Jan might happen to know how to use it though.
Bryne Chipembe
Bryne Chipembe 2021 年 12 月 11 日
Hi Walter
Thanks for the swift response. I dont see the complier installed on my PC, all I can see is that MATLAB Component Runtime. I dont mind using a newer complier, I dont think that would affect much would it?
Walter Roberson
Walter Roberson 2021 年 12 月 11 日
You can't buy the compiler for a release that old these days -- at least not directly. If you had the compiler for any newer version, the license would authorize you to use the compiler for the older release.
Once you get to roughly r2010a, the compiler would start complaining that your code will not work for 64 bit versions. There are command line options for backwards compatibility, but they will not get you past R2015b -- because R2015b is the last 32 bit version of MATLAB, and your code would definitely have to be touched up to be compatible with 64 bit MATLAB.
At the moment, I have no information about which version of LabView requires which version of MATLAB. You are using a 32 bit version of LabView at the moment, and that would not be able to call 64 bit .dll (operating system limitation.)
R2015a introduced MATLAB Compiler SDK as a product, and for your particular purpose (creating a DLL) you would need that product as well as MATLAB Compiler. Before R2015a, Mathworks offered some products with "Builder" in their name; unfortunately my memory is not currently filling in which of the "Builder" products would have been suitable.
Back in R14SP1, the compiler technology was completely different and the "Builder" products were not relevant.
Bryne Chipembe
Bryne Chipembe 2021 年 12 月 11 日
So I see that in the folder that holds this .dll there is another folder named complier. I have no idea what the files in here do. I believe that I can get the old compiler .exe used back then, there must be a CD lying around somewhere.
I've attached the folder here, please help if you can.
Walter Roberson
Walter Roberson 2021 年 12 月 11 日
If you have the appropriate software package installed, then you should just have to cd to the directory and execute
build_reverse_hex_dll
This will invoke mcc and mbuild to do the compiling.
Back in those days, mcc and mbuild were both parts of MATLAB Compiler; these days mcc is part of MATLAB Compiler and mbuild is part of MATLAB Compiler SDK.
If you do not have MATLAB Compiler installed, then you have a problem. The Component Runtime you see is definitely not able to compile anything.
Bryne Chipembe
Bryne Chipembe 2021 年 12 月 12 日
Thanks Walter,
  1. How do I use the argument specified in the .c file
Arguments: "-B" "macro_default" "link:lib" "reverse_wrapper.m"
"lib:libreversehex" "-T" "link:lib" "reverse_wrapper.m"
2. is there anything useful in the file \libreversehex_mcr\toolbox\compiler
Just executing "build_reverse_hex_dll" didnt work, windows goes off looking for the compiler and cannot find it I believe. I cant help but wonder why that compiler folder would be in there.
Walter Roberson
Walter Roberson 2021 年 12 月 12 日
The compiler directory contains the .m and .fig that you were compiling to make the GUI application. It does not have any trace of tools to do the compiling with
You do not use those Arguments.
What happened is that at some point the MATLAB Compiler was used to compile a .m file into a .c file. The Arguments list you see inside the .c file is a record of the command line arguments that were used to generate the .c from the .m
Inside the C code, I notice sections such as
typedef struct {
int32 dimSizes[2];
float64 Numeric[1];
} TD2;
Those sections are not compatible with 64 bit MATLAB, as dimensions are now uint64 . But I think the code might be okay with 32 bit MATLAB (up to R2015b)... though you might have to use some command line switches.
Was it a .c file or a .m file that you changed? If it was the .c file only, then we just might be able to compile for you... maybe... with some effort.
Unfortunately I do not have a Windows development system (licensing conflicts.)
Bryne Chipembe
Bryne Chipembe 2021 年 12 月 12 日
Yes I only changed the .c File "reversehex.c" the dll is running on an old 32bit windows xp machine. In actual fact its being used by a 32bit labview application.
Walter Roberson
Walter Roberson 2021 年 12 月 12 日
I suspect that if you compile the .c to a .obj and link against the proper libraries that you could get the necessary .dll
Bryne Chipembe
Bryne Chipembe 2021 年 12 月 12 日
what compiler do I use to compile the .c File?
You have me well confused now. So no need for the MATLAB complier?
This is more messed up than I imagined.
Walter Roberson
Walter Roberson 2021 年 12 月 12 日
編集済み: Walter Roberson 2021 年 12 月 12 日
These days, MATLAB Compiler is a marketting name for a product that takes .m files and generates a data structure that gets embedded into an .exe, along with a copy of the MATLAB computation engine (same one used to calculate for interactive MATLAB.)
Back in the release you were using, MATLAB Compiler was able to generate C code, that you then compiled with a handy external compiler. You already have that C code now. Back then you could have compiled with lcc-32 (a free compiler that was supplied with MATLAB with some products), or Visual C 6.0 Professional, or Visual C 7.1 Professional. You can get lcc-win32 from https://lcc-win32.services.net/
Bryne Chipembe
Bryne Chipembe 2021 年 12 月 12 日
編集済み: Bryne Chipembe 2021 年 12 月 13 日
Yes the problem here is that the header files listed in the .cfile "mat.h" and "libreversehex.h" are not in the project folder.
Let me try finding a matlab complier that will work, using that build script.
Bryne Chipembe
Bryne Chipembe 2021 年 12 月 13 日
Yes so i found a Matlab 7.1 installation and ran the build script but that didnt work, instead of using the altered .cfile the mcc/mbuild create a new .c File that doesnt have the functions that labview is looking for.
I then tried just using lcc to create a dll, I included matrix.h and mat.h which are in the Matlab include directory, however the compiler keeps complaining about "undefined reference to "
mclInitializeApplication
libreversehexInitialize
mxCreateDoubleMatrix
mxCreateDoubleScalar
mxGet
mlfReverse_wrapper
mxDestroyArray
GetExceptionCode
which file would I have to link to get these into the dll?

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

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeC Shared Library Integration についてさらに検索

製品

リリース

R14SP2

質問済み:

2021 年 12 月 11 日

コメント済み:

2021 年 12 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by