load C/C++ DLL on a computer without internet access
Show older comments
I want to use a publicly-produced C/C++ DLL to perform atmospheric modeling on a computer that for security reasons cannot (ever) have internet access.
When I use the loadlibrary command to load the DLL, MATLAB prompts me to go online and install their recommended C/C++ compiler, which then fails because no Internet access. I've tried to manually download the add-on software but am unable to.
Is there a workaround for this? For example, can I permanently compile the DLL into a MEX file?
Accepted Answer
More Answers (1)
Guillaume
on 7 Sep 2019
Most likely, the library is C not C++. They're two very different things and loadlibrary cannot load C++ dlls.
You can generate a protofile on a computer with a compiler installed and use that protofile instead of the header file.
%on a computer with a compiler
loadlibrary('somedllfile.dll', 'someheaderfile.h', 'mfilename', 'myprotofile');
copy myprotofile on the other computer, then:
loadlibrary('somedllfile.dll', @myprotofile);
to load the library.
4 Comments
Justin Henrie
on 8 Sep 2019
Guillaume
on 8 Sep 2019
Ah, sorry, I admit I didn't test it. I was certain that the proto file removed the need for the compiler since the h file would have already been parsed. I'm not sure why matlab needs a compiler just to invoke a dll.
One option would be to create a mex wrapper to call the dll indeed (you'd need the mex file and the dll on the offline computer) but you should be able to install mingw offline.
On the online computer, start the add-on manager (on the home tab, in the environment section) and search for mingw. Select MATLAB Support for MinGW-w64 C/C++ Compiler (probably the first add-on in the list) and where it says Install select Download only instead. Once downloaded, you can copy the whole download to the offline computer and follow the instructions in the readme.txt to install the compiler.
Justin Henrie
on 10 Sep 2019
Guillaume
on 11 Sep 2019
The instructions I gave to install mingw is for an add-on provided by directly by mathworks including mingw. It's just one package. This may make it easier to get approval.
However, I do understand that it can be problematic. In that case, your best root is indeed a mex wrapper(s) for the dll. It wouldn't be complicated to create. You either create a mex file per function you want to wrap or have a single mex function that that takes the dll function name and required parameters. Either way all the mex does is call the required dll function.
Categories
Find more on MATLAB Support for MinGW-w64 C/C++ Compiler in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!