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

3 ビュー (過去 30 日間)
Justin Henrie
Justin Henrie 2019 年 9 月 7 日
回答済み: Justin Henrie 2019 年 9 月 17 日
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?

採用された回答

Justin Henrie
Justin Henrie 2019 年 9 月 17 日
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.

その他の回答 (1 件)

Guillaume
Guillaume 2019 年 9 月 7 日
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 件のコメント
Justin Henrie
Justin Henrie 2019 年 9 月 10 日
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!
Guillaume
Guillaume 2019 年 9 月 11 日
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.

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by