load C/C++ DLL on a computer without internet access

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

Just got this from MATLAB support. It works. Guillame was close!
Please perform the following steps to generate and use a "Prototype" file and a "thunk" file in order to load the DLL without using a compiler.
1) On the computer with the compiler, execute the following command in the MATLAB Command Window to create the "Prototype" file and the "thunk" file. This step assumes that the DLL you wish to load is called "somedllfile.dll" and that the corresponding header file is called "someheaderfile.h".
>>loadlibrary('somedllfile.dll', 'someheaderfile.h', 'mfilename', 'someprototypefile');
2) Transfer both the generated "Prototype" file ("someprototypefile.m") and the generated "thunk" file ("somedllfile_thunk_pcwin64.dll") to the computer without the compiler. It is important to include the "thunk" file in this transfer, in addition to the "Prototype" file.
3) On the computer without the compiler, execute the following command in the MATLAB Command Window to load the DLL.
>>loadlibrary(‘somedllfile.dll’,@someprototypefile)
In this step, it is important to use the '@' symbol before the name of the "Prototype" file and to remove any quotes around the name of "Prototype" file.
After completing these steps, the library should be successfully loaded.

More Answers (1)

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

Thanks very much for the rapid answer. I followed your instructions and was able to generate a *.m prototype file, but when I tried to loadlibrary on the non-internet-enabled computer I still got the following error message:
>> loadlibrary('propa64.dll','mexpropa.m')
Error using loadlibrary
No supported compiler was found. You can install the freely available MinGW-w64 C/C++ compiler; see Install MinGW-w64 Compiler. For more options, visit
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.
Unfortunately downloading the MinGW Compiler is problematic for me for a couple of reasons:
  1. It's open-source software, which is hard to get approved for the secure computer
  2. Its install file is an exe, which is hard to get approved for the secure computer
  3. I can't even seem to download it right now from sourceforge anyway (not sure why).
I agree that it is strange that the compiler is needed to merely invoke a (compiled) dll. I wish it were not so!
Thanks again for your attention to this admittedly niche problem!
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.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!