fortran - 包含 IEEE_GET_ROUNDING_MODE 的库的 gfortran 链接器参数
问题描述
我正在尝试为区间算术编写一个简单的 Fortran 库作为练习。我想明确设置舍入模式,做一些工作,然后将舍入模式恢复到原来的样子。gfortran
但是,在使用,gcc
的 Fortran 前端进行编译时,我无法确定需要将哪个库链接到生成的可执行文件。
! get_rounding_mode.f03
! print the rounding mode
program get_rounding_mode
f = IEEE_GET_ROUNDING_MODE()
print *,f
end program get_rounding_mode
尝试可能可行的最简单的事情给了我
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
.
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
解决方案
IEEE_GET_ROUNDING_MODE
不是函数。这是一个子程序。你需要做类似的事情
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 none
和声明x
推荐阅读
- apache - 在 MacOS 上的 Apache 中启用 CGI
- reactjs - 如何在 React 中自定义 Reactstrap 按钮?
- git - .gitignore 到底是什么
- apache-camel - 无法解析端点:jetty://http://localhost:8888/sample,原因是:没有找到带有方案的组件:jetty
- kubernetes - 使用 AWS Container Insights 监控 Kubernetes CronJob 完成情况
- php - LARAVEL 得到错误 500 | SmarterASP.NET 托管服务器中的服务器错误
- c++ - 如何将双精度值直接转换为 PQ^-1 模 MOD,其中 q 与 MOD 互质
- perforce - 检查给定的 perforce 标签是否存在
- python - 检索对象
- excel - 使用 VBA 在 Google 表单中选择下拉列表选项