mex fortran code containing intrinsic function using Intel fortran compiler

2 ビュー (過去 30 日間)
Duy Nguyen
Duy Nguyen 2019 年 9 月 24 日
編集済み: Duy Nguyen 2019 年 9 月 25 日
Hi,
I'm trying to mex a fortran code using the Intel Parallel studio XE 2019 with microsoft visual studio 2015 compiler. My fortran code calls intrinsic functions cosd, sind, and atand. However, the linker keeps complaining that these are unresolved external symbols. Are there libraries that I need to link in during the mex that will define these intrinsic functions? Thanks.
Error using mex
Creating library rcssig.lib and object rcssig.exp
read_reftab.obj : error LNK2019: unresolved external symbol COSD referenced in
function READ_REFTAB
body_to_range.obj : error LNK2001: unresolved external symbol COSD

採用された回答

A.B.
A.B. 2019 年 9 月 25 日
編集済み: A.B. 2019 年 9 月 25 日
cosd, sind, atand, are NOT part of the Fortran standard, they are GNU extensions to the Fortran language and not understandable by Intel. These GNU functions take the angle in degree instead of radians (which is the deafult Fortran standard for sin, cos, atan). If you want to compile the files by Intel, multiply the arguments of all instances of cosd, sind by pi/180 = 0.01745329251, which converts the angles in degrees to radians, then replace all of the instances of cosd, sind, with cos, sin respectively, which are part of the Fortran standard and that should resolve the error.
As for atand, this function returns angle in degrees, so you will have to replace atand() with 57.2957795131 * atan()
where 57.2957795131 = 180/pi
  2 件のコメント
James Tursa
James Tursa 2019 年 9 月 25 日
編集済み: James Tursa 2019 年 9 月 25 日
From the Intel Fortran website:
Also note that OP specifically stated his compiler understands cosd( ) just fine in a standalone compile, just not in a mex compile.
Duy Nguyen
Duy Nguyen 2019 年 9 月 25 日
編集済み: Duy Nguyen 2019 年 9 月 25 日
Perfect! Thank you so much.
Wished I had read that earlier from the Fortran website, would have saved me tons of time trying to figure out why cosd compiles in standalone mode but not in mex :) Thank you!!!!!

サインインしてコメントする。

その他の回答 (1 件)

James Tursa
James Tursa 2019 年 9 月 24 日
編集済み: James Tursa 2019 年 9 月 24 日
Can you post the offending code? Maybe you are calling it with a non-real argument and the compiler is complaining that it can't find a specific function for your specific argument type.
How are you doing the compiling and linking? With the mex command, or building from within the Visual Studio environment?
  1 件のコメント
Duy Nguyen
Duy Nguyen 2019 年 9 月 24 日
Hi,
This is a sample call that I make: pitch(1,1)=COSD(pitch_angle), where pitch_angle is a real number.
The code compiles and runs just fine within the Visual Studio 2015 and 2017 environment. But when I try to mex it within Matlab, I get the undefined external error. I looked at the build log file generated by the Visual Studio 2015 compiler and see no library that I need to link in, so I can't figure out what the Mex is looking for to resolve cosd.
Thanks.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by