インターフェイスの生成
この例では、ヘッダー ファイル matrixOperations.hpp
で宣言され、C++ ソース ファイル matrixOperations.cpp
で定義された C++ ライブラリに対する MATLAB® ライブラリ定義ファイルを作成する方法を示します。
選択した C++ コンパイラの確認
MathWorks でサポートされている任意の C++ コンパイラを使用できます。C++ コンパイラがあることを確認するには、次のように入力します。
mex -setup cpp
この例では、C++ 言語のコンパイルに MinGW64 Compiler (C++) を使用します。
定義ファイルの生成
C++ ライブラリのアーティファクトの名前とパスを識別します。既定では、ヘッダー ファイルの名前 (matrixOperations
) がライブラリの名前 (libname
) として使用されます。
productPath = fullfile(matlabroot,'extern','examples','cpp_interface'); hppFile = 'matrixOperations.hpp'; cppFile = 'matrixOperations.cpp';
定義ファイルを生成します。MATLAB で定義ファイル definematrixOperations.m
が生成されます。
clibgen.generateLibraryDefinition(fullfile(productPath,hppFile), ... "SupportingSourceFiles",fullfile(productPath,cppFile), ... "OverwriteExistingDefinitionFiles",true, ... "ReturnCArrays",false) % treat output as MATLAB arrays
C++ compiler set to 'MinGW64 Compiler (C++)'. Definition file definematrixOperations.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 definematrixOperations.m. To build the interface, call build(definematrixOperations).
MATLAB で定義ファイル definematrixOperations.m
が生成されます。出力メッセージのリンクをクリックしてファイルを開き、次の手順に進みます。
定義ファイルを開く
出力メッセージのリンクをクリックして、生成されたライブラリ定義ファイルを開きます。その後、次の手順に進みます。