Windows でのインターフェイスの生成
この例では、Windows® のインポート ライブラリ ファイルを含むライブラリのライブラリ定義ファイルを作成します。
選択した C++ コンパイラの確認
MathWorks でサポートされている任意の C++ コンパイラを使用できます。この例では、C++ 言語のコンパイルに MinGW64 Compiler (C++) を使用します。C++ コンパイラがあることを確認するには、次のように入力します。
mex -setup cpp
定義ファイルの生成
C++ ライブラリのアーティファクトの名前とパスを識別します。
productPath = fullfile(matlabroot,"extern","examples","cpp_interface"); hppFile = "matrixOperations.hpp"; hppPath = productPath; libFile = "matrixOperations.lib"; libname = "matrixlib";
コンパイル済みライブラリを識別します。選択したコンパイラに基づいて、次のいずれかのステートメントのコメントを解除して実行します。
%libPath = fullfile(productPath,"win64","mingw64"); %libPath = fullfile(productPath,"win64","microsoft");
定義ファイルを生成します。MATLAB® で定義ファイル definematrixlib.m
が生成されます。
clibgen.generateLibraryDefinition(fullfile(hppPath,hppFile), ... "Libraries",fullfile(libPath,libFile), ... "PackageName",libname, ... "ReturnCArrays",false, ... % treat output as MATLAB arrays "OverwriteExistingDefinitionFiles",true)
C++ compiler set to 'MinGW64 Compiler (C++)'. Definition file definematrixlib.m contains definitions for 10 constructs supported by MATLAB. - 5 constructs are fully defined. - 5 constructs partially defined and commented out. To include the 5 undefined constructs in the interface, uncomment and complete the definitions in definematrixlib.m. To build the interface, call build(definematrixlib).
定義ファイルを開く
出力メッセージのリンクをクリックして、生成されたライブラリ定義ファイルを開きます。その後、次の手順に進みます。