フィルターのクリア

C-MEX(fortran)のビルドエラー "undefined reference to `ATMOS' collect2.exe: error: ld returned 1 exit status" を解決するためにはどうすればよいですか.

33 ビュー (過去 30 日間)
N.Y.
N.Y. 2024 年 4 月 30 日
回答済み: N.Y. 2024 年 5 月 14 日
C-MEX Calling Fortran (S-function) のサンプルsfun_atmos(https://jp.mathworks.com/help/simulink/sfg/s-function-examples.html)に関して,
mex('-v', '-c', fullfile(matlabroot,'toolbox','simulink','sfuntemplates','srcFortran','sfun_atmos_sub.F'))
mex('-v', ['-L"', fullfile(getenv('IFORT_COMPILER24'), 'compiler', 'lib', 'intel64_win'), '"'], fullfile(matlabroot,'toolbox','simulink','sfuntemplates','srcFortran','sfun_atmos.c'), 'sfun_atmos_sub.obj')
このようにコマンドウィンドウで実行したところ,コンパイルと.objファイルの出力には成功したのですが,ビルド時に以下のようなエラーが出てしまいます.
次を使用中のエラー: mex
C:\Users\SSHINS~1\AppData\Local\Temp\mex_1126126941339403_22156\sfun_atmos.obj:sfun_atmos.c:(.text+0x142): undefined reference to `ATMOS'
collect2.exe: error: ld returned 1 exit status
使用環境としては,次の通りです.
windows 10 64bit
MATLAB 2024a
このサンプルに習って自身のfortranサブルーチンの組み込みに挑戦しようと考えておりましたので,何が原因でこのようなエラーが発生してしまうのか,また,どのようにすると解決できるのか知りたいです.
どなたかご教授戴きたく,よろしくお願いいたします.

採用された回答

N.Y.
N.Y. 2024 年 5 月 14 日
一応,解決したので...
gccベースのコンパイラを使用する際,sfun_atmos.cの60行目のコメントは正しくないようです.
したがって以下の文をコメントアウトすることで,コンパイルが成功しました.
#ifdef _WIN32
#define atmos_ ATMOS
#endif

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFortran からの MATLAB の呼び出し についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!