首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >包含IEEE_GET_ROUNDING_MODE的库的gfortran链接器参数

包含IEEE_GET_ROUNDING_MODE的库的gfortran链接器参数
EN

Stack Overflow用户
提问于 2018-12-27 21:14:36
回答 1查看 141关注 0票数 2

我试图为区间算术编写一个简单的Fortran库作为练习。我想显式设置舍入模式,做一些工作,然后将舍入模式恢复到原来的状态。但是,在使用gfortran (gcc的Fortran前端)编译时,我不知道哪个库需要链接到生成的可执行文件。

代码语言:javascript
复制
! get_rounding_mode.f03
! print the rounding mode

program get_rounding_mode
  f = IEEE_GET_ROUNDING_MODE()
  print *,f
end program get_rounding_mode

尝试最简单可行的方法让我

代码语言:javascript
复制
gfortran get_rounding_mode.f03 
/usr/bin/ld: /tmp/ccTLaxeN.o: in function `MAIN__':
get_rounding_mode.f03:(.text+0x20): undefined reference to `ieee_get_rounding_mode_'
collect2: error: ld returned 1 exit status
Exit 1

通过到处查找ieee_get_rounding,我找到了它,但我不知道如何引导gfortran链接它,因为它似乎已经在libgfortran中了。

代码语言:javascript
复制
find /usr/ -exec nm --print-file-name '{}' '+' 2>&1 | grep 'ieee_get_rounding'
/usr/lib/libgfortran.so.5:000000000023edc0 T __ieee_arithmetic_MOD_ieee_get_rounding_mode
/usr/lib/libgfortran.so:000000000023edc0 T __ieee_arithmetic_MOD_ieee_get_rounding_mode
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-27 22:06:32

IEEE_GET_ROUNDING_MODE不是一个函数。这是一个子程序。你需要做的事情是

代码语言:javascript
复制
program get_rounding_mode
   use ieee_arithmetic
   implicit none
   ieee_rounding_type mode
   real x
   if (ieee_support_rounding(x)) then
      call ieee_get_rounding_mode(mode)       ! Get current rounding mode
      call ieee_set_rounding_mode(IEEE_TO_UP) ! Set rounding up
      !
      ! Do your work here!
      !
      call ieee_set_rounding_mode(mode)       ! Reset rounding mode
   end if
 end program get_rounding_mode

喔,忘了implicit nonex的声明了

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53950936

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档