MEX ファイルで “Hello World” を表示するサンプルはありますか?
13 views (last 30 days)
Show older comments
MathWorks Support Team
on 7 Aug 2019
Edited: MathWorks Support Team
on 13 Nov 2025 at 0:48
最もシンプルなMEXファイルとして、Hello World を表示するMEXファイルを作成したいのですが、サンプルのソースファイルがあるか、教えてください。
Accepted Answer
MathWorks Support Team
on 13 Nov 2025 at 0:00
Edited: MathWorks Support Team
on 13 Nov 2025 at 0:48
MEX ファイルを作成する場合、C のソースコードでは
・mex.h の include
・ゲートウェイルーチンと呼ばれる mexFunction 関数の記述
が必要となります。言い換えますと、これが満たされれば、とりあえず MEX ファイルを作成することができます。
■ ソースファイル myhello.c
/*********************************************************/
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mexPrintf("%s\n", "Hello World");
}
/*********************************************************/
■ MEX 化
>> mex myhello.c
'MinGW64 Compiler (C)' でビルドしています。
MEX は正常に完了しました。
■ 実行
>> myhello
Hello World
0 Comments
More Answers (0)
See Also
Categories
Find more on C MEX ファイル アプリケーション 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!