我正在为一个私有项目编译库,这取决于许多库.具体来说,其中一个依赖项是使用Fortran编译的.在某些情况下,我已经看到编译的依赖项g77,在其他人看到它编译时gfortran.然后我的项目./configure要么与其中任何一个-lg2c或者链接-lgfortran,但到目前为止我一直在手工做.
如果有可能,我怎样才能从查看依赖库(通过例如nm或其他一些实用工具?),找到所使用的编译器g77(然后我将-lg2c在我的链接选项中使用)或gfortran(然后我'会用-lgfortran吗)?
提前致谢!
我正在尝试将错误检查纳入我正在编写的纯过程中.我想要像:
pure real function func1(output_unit,a)
implicit none
integer :: a, output_unit
if (a < 0) then
write(output_unit,*) 'Error in function func1: argument must be a nonnegative integer. It is ', a
else
func1 = a/3
endif
return
end function func1
Run Code Online (Sandbox Code Playgroud)
但是,不允许纯函数将IO语句赋予外部文件,因此我尝试将单元号传递给函数,例如output_unit = 6,这是默认输出.gfortran仍然认为这是非法的.有没有解决的办法?是否有可能使函数成为派生类型(而不是real此处的内部类型),在出现错误时输出字符串?
我需要pure在使用gfortran编译的fortran程序中调试一些函数.有没有办法忽略的pure语句,所以我可以使用write,print在这些等pure功能,不花大力气?不幸的是,只是删除pure声明是不可能的.
我最近学会了如何在Fortran中使用基本文件,我认为它很简单:
open(unit=10,file="data.dat")
read(10,*) some_variable, somevar2
close(10)
Run Code Online (Sandbox Code Playgroud)
所以我无法理解为什么我写的这个函数不起作用.它编译得很好但是当我运行它打印:
fortran runtime error:end of file
Run Code Online (Sandbox Code Playgroud)
码:
Function Load_Names()
character(len=30) :: Staff_Name(65)
integer :: i = 1
open(unit=10, file="Staff_Names.txt")
do while(i < 65)
read(10,*) Staff_Name(i)
print*, Staff_Name(i)
i = i + 1
end do
close(10)
end Function Load_Names
Run Code Online (Sandbox Code Playgroud)
我正在使用Fortran 2008和gfortran.
我通常运行我的代码ifort,但在实现过程中,我更喜欢编译和测试,gfortran因为我发现它比它的intel更严格.
在打开编译选项时-Wall,我收到以下警告:
Warning: Nonconforming tab character at (1)
有没有办法在使用相同的编译选项时使这一特定警告静音?请注意,我不希望用空格替换选项卡.如果没有办法解决这个问题,那么答案"不可能"就足够了.
我一直在使用MinGW和GNU Fortran编译器,以便在Windows上编译Fortran程序,这一直是一种成功的方法.但是,我在过去4天内收到以下错误:
The application was unable to start correctly (0xc000007b). Click OK to close the application.
该错误仅在运行我自己编写的应用程序时发生,并且我使用MinGW/gfortran组合编译.使用Visual Studio和iFort进行编译时,运行应用程序没有问题.这个错误似乎是追溯性的:很久以前使用gfortran编译并且运行完美的应用程序直到现在也会中断,即使我没有重新编译它们.这让我觉得它是一个动态库问题.在线搜索表明它可能是64位dll和32位应用程序之间的兼容性问题
我正在使用Windows 7.在开始解决问题之前我记得做的最新事情之一是尝试更新MinGW; 我使用了mingw-get update和mingw-get upgrade命令行.
在网上浏览后,我尝试了以下修复:
- 重新安装了Visual C++运行时环境
- 重新安装了.NET框架
- 下载并替换了一堆.dll,如mscvr100.dll,mscvr100d.dll等...
- 卸载并重新安装重新安装MinGW以确保我有最新的gcc版本
- 在一个简单的应用程序上运行Dependency Walker("Hello World!"类型程序)
Dependency Walker告诉我无法找到多个.dll(完整列表:API-MS-WIN-APPMODEL-RUNTIME-L1-1-0.DLL,API-MS-WIN-CORE-WINRT-ERROR-L1-1 -0.DLL,API-MS-WIN-CORE-WINRT-L1-1-0.DLL,API-MS-WIN-CORE-WINRT-ROBUFFER-L1-1-0.DLL,API-MS-WIN-CORE -WINRT-STRING-L1-1-0.DLL,API-MS-WIN-SHCORE-SCALING-L1-1-1.DLL,DCOMP.DLL,GPSVC.DLL,IESHIMS.DLL).
它还以红色突出显示了libquadmath-0.dll(libgfortran-3.dll似乎依赖于它).实际上,似乎libquadmath-0.dll是一个32位程序中间的64位DLL.当用Dependency Walker打开.dll时,我可以看到这个库中的所有模块都是x86,除了库本身是x64(DW的CPU列).我不确定这是如何可行的/如何解决它.该库位于Python/Anaconda文件夹中(几周前我安装了Python和Anaconda,当时没有出现问题).
如果有人知道如何在不重新安装Windows的情况下让环境再次运行,我将非常感激!谢谢!!
为了遍历Fortran中的链表,我使用指向当前元素的指针,该元素移动到循环内的下一个元素.尝试pure在对所述链表执行操作的函数内应用此操作会导致错误.
例:
module list
implicit none
! Node
type n_list
integer :: val
type(n_list),pointer :: next => NULL()
end type
! Linked list
type t_list
type(n_list),pointer :: head
end type
contains
pure function in_list( list, val ) result(res)
implicit none
class(t_list),intent(in) :: list
integer,intent(in) :: val
logical :: res
type(n_list),pointer :: cur
res = .true.
! Traverse the list
cur => list%head
do while ( associated(cur) )
if ( cur%val == val ) return
cur => cur%next
enddo …Run Code Online (Sandbox Code Playgroud) 我尝试安装一些编译器.我在笔记本电脑中使用Centos 6.我已经安装了gcc,即"GNU"C编译器.我还需要安装gfortran,但是当我输入时yum install gfortran,我收到了消息no package gfortran available.
你知道如何安装fortran编译器吗?
我正在尝试使用 来学习 Fortran2018 gfortran。在使用指针时,我注意到似乎没有测试空指针的工具。所以我有两个问题:
更实际地说,在下面的代码片段中:我们如何在执行过程中的任何时刻找出分配给p是否“安全”?allocate(可能会想象一个更复杂的、nullify和语句序列deallocate。)
program test
implicit none
real, pointer :: p
! p = 333.333 ! Segfault, p is neither defined, nor allocated
! Since p is not defined, checking whether it's
! associated to a target gives arbitrary results:
print *, "Start: Pointer p associated? ", associated(p) ! Result: True or False
nullify(p) ! Now p is defined, but `null`
print *, "Nullyfied: …Run Code Online (Sandbox Code Playgroud)