外部インタフェース/API | ![]() ![]() |
UNIXでの設定のテスト
システムが適切にMEX-ファイルを作成するように設定されているかどうかをチェックする最速の方法は、実際のプロセスを試してみることです。例として、<matlab>/extern/examples/mex
ディレクトリにCのソースコードyprime.c
とそのFortran版yprimef.F
およびyprimefg.F
があります。ここで、<matlab>
は、システム上でMATLABがインストールされている最上位のディレクトリを表わします。
例題のソースファイルyprime.c
またはyprimef.F
とyprimefg.F
をUNIX上でコンパイル、リンクするためには、まずそれらのファイルをローカルディレクトリにコピーし、それからローカルディレクトリにディレクトリの変更 (cd
)をしなければなりません。
mex yprime.c
これは、システムコンパイラを使って、システムに対応する拡張子をもつyprime
というMEX-ファイルを作成します。
M-functionのようにyprime
を呼び出すことができます。
yprime(1,1:4) ans = 2.0000 8.9685 4.0000 -1.0947
例題プログラムのFortran版をFortranコンパイラを使って行うためには、MATLABプロンプトでつぎのようにタイプします。
mex yprimef.F yprimefg.F
MATLABプロンプトからmex
スクリプトを実行するのに加えて、システムプロンプトからもスクリプトを実行できます。
コンパイラの選択
デフォルトのコンパイラを変更するには、別のオプションファイルを選択します。つぎのコマンドを使って行うことができます。
mex -setup Using the 'mex -setup' command selects an options file that is placed in ~/matlab and used by default for 'mex'. An options file in the current working directory or specified on the command line overrides the default options file in ~/matlab. Options files control which compiler to use, the compiler and link command options, and the runtime libraries to link against. To override the default options file, use the 'mex -f' command (see 'mex -help' for more information). The options files available for mex are: 1: <matlab>/bin/gccopts.sh : Template Options file for building gcc MEXfiles 2: <matlab>/bin/mexopts.sh : Template Options file for building MEXfiles using the system ANSI compiler Enter the number of the options file to use as your default options file:
番号を入力し、Returnを押してシステムに対する適切なオプションファイルを選択します。オプションファイルがMATLABディレクトリにない場合は、システムはオプションファイルがユーザのmatlab
ディレクトリにコピーされたことを示すメッセージを表示します。オプションファイルがmatlab
ディレクトリに既に存在する場合は、システムは上書きするかどうかを尋ねます。
setupオプションを使うと、デフォルトコンパイラをリセットするので、mex
スクリプトを使うたびに新たなコンパイラが利用されます。
![]() | MEX-ファイルの作成 | Windowsでの設定のテスト | ![]() |