这是我第一次尝试使用makefile编译FORTRAN代码.操作系统是Ubuntu 12.04 LTS 64位.我遇到了以下错误:
gfortran -o przm3123.exe canopy.o chem.o cnfuns.o cropdate.o datemod.o debug.o debug_cn.o f2kcli.o floatcmp.o furrow.o general.o i_errchk.o infnan.o inivar.o ioluns.o iosubs.o lambertw.o m_readvars.o utils.o wind.o fcscnc.o przm3.o rsexec.o rsinp1.o rsinp2.o rsinp3.o rsmcar.o rsmisc.o rsprz1.o rsprz2.o rsprz3.o rsprzn.o rsutil.o rsvado.o -L ../libanne4.0/lib -lwdm -ladwdm -lutil
/usr/bin/ld: cannot find -lwdm
/usr/bin/ld: cannot find -ladwdm
collect2: ld returned 1 exit status
make: *** [przm3123.exe] Error 1
Run Code Online (Sandbox Code Playgroud)
makefile中的关键元素是:
przm2_LIBS = -L ../libanne4.0/lib -lwdm -ladwdm -lutil
Run Code Online (Sandbox Code Playgroud)
我有什么办法可以解决这个错误吗?我应该尝试其他编译器吗?
我有一个我想分发的Fortran程序,所以我想在gfortran库中静态链接.
如果我使用以下标志编译程序:
gfortran -o myprog -static-libgfortran -static-libgcc myprog.f
Run Code Online (Sandbox Code Playgroud)
otool告诉我它在大多数gofrtran库中是静态链接的,但不是libquadmath:
otool -L myprog
/usr/local/gfortran/lib/libquadmath.0.dylib (compatibility version 1.0.0, current v
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
Run Code Online (Sandbox Code Playgroud)
有一个静态的libquadmath库/usr/local/gfortran/lib/libquadmath.a,但是我尝试的每个链接行总是以完整的静态链接(OSX不支持)或libquadmath的动态链接结束.
我已经设法通过从/ usr/local/gfortran/lib /中删除libquadmath.0.dylib和libquadmath.dylib来创建我想要的东西,然后链接器拉入静态库.
然而,至少可以说这看起来有点笨拙.
任何人都可以建议一个更优雅的方式吗?
谢谢!
我正在使用Ubuntu 10.04并尝试编译一些使用gfortran的代码.在某些时候,Makefile会:
-L. -lgfortran
Run Code Online (Sandbox Code Playgroud)
我得到了错误
/usr/bin/ld: cannot find -lgfortran
Run Code Online (Sandbox Code Playgroud)
虽然安装了:
ldconfig -p | grep fortran
libgfortran.so.3 (libc6,x86-64) => /usr/lib/libgfortran.so.3
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
PS:Makefile:
## FLAGS
CC:= gcc
C++:= g++
CFLAGS:= -c -O -Dintel -g
FC:= gfortran
FFLAGS:= -c -O -cpp -g
LD:= g++
LDFLAGS:= -O
WETTER_CGAL_FLAGS:= -g
#WETTER-Data
WETTER_cgal: weather.cpp surface_alg.h $(WETTER_CGAL_OBJECTS) WATT_interface.h data.cpp
$(C++) $(WETTER_CGAL_FLAGS) -c weather.cpp -frounding-math
$(C++) -c data.cpp -frounding-math
$(LD) $(WETTER_CGAL_OBJECTS) weather.o data.o -o WETTER_cgal -L. -lgfortran -lgmp -lCGAL -frounding-math -fp-model
Run Code Online (Sandbox Code Playgroud) 我明白gfortran可以编译f90或f95吗?它如何知道它正在编译哪一个?还可以编译f77代码吗?ubuntu已经有了fortran编译器,还是需要下载gfortran?
有没有办法在gfortran编译器中禁用行长度限制?我正在从ifort移植到gfortran,我想知道是否有一个简单的方法可以不经过代码并在需要的地方手动引入行继续.
我在mac osx mavericks上使用gfortran编译器.我已经安装了Xcode和命令行工具.我正在尝试使用gfortran编译一个简单的helloworld程序来测试一切是否正常,但遗憾的是它不起作用.错误消息似乎表明我没有主要功能,但我没有在代码中看到错误:
program hello
print *, "Hello World!"
end program hello
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用编译时
gfortran helloworld.f
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Undefined symbols for architecture x86_64:
"start", referenced from:
-u command line option
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
我不明白什么是错的,我处于绝望的边缘.我尝试使用gfortran 4.8.2以及gfortran 4.9.0,我尝试重新安装Xcode和命令行工具,但似乎没有任何工作.
我知道有人问过类似的问题,但我无法找到问题的解决方案.即使我有一个草率的解决方法,我会很高兴,只要我能让编译器运行...
我需要使用gfortran来编译依赖的库ieee_arithmetic.但是,发现gfortran无法识别此模块.
例如使用代码 a.f90
program test
use,intrinsic :: ieee_arithmetic
real :: x
read *, x
if (ieee_is_nan(x)) then
print *, "Nan"
else
print *, "Not NaN"
end if
end program test
Run Code Online (Sandbox Code Playgroud)
编译时我有以下消息
$ gfortran a.f90
a.f90:2.19:
use,intrinsic :: ieee_arithmetic
1
Fatal Error: Can't find an intrinsic module named 'ieee_arithmetic' at (1)
Run Code Online (Sandbox Code Playgroud)
我怎样才能让gfortran知道ieee_arithmetic内在模块的位置?
发现ifort能够使用该ieee_arithmetic模块.但我希望为这个案子做好准备.
我想检查是否已经定义了派生类型中的指针.我写了以下简单的代码来向您展示我的问题:
program test
implicit none
type y
real(8), pointer :: x(:)
end type y
type(y), pointer :: w(:)
allocate(w(2))
allocate(w(1)%x(2))
write(*,*) associated(w(1)%x), associated(w(2)%x)
end program test
Run Code Online (Sandbox Code Playgroud)
使用gFortran 4.4.1编译此代码并在Ubuntu上运行它会得到结果:
T F
Run Code Online (Sandbox Code Playgroud)
而在Windows Vista上使用英特尔Fortran编译器11.0编译的相同代码提供:
T T
Run Code Online (Sandbox Code Playgroud)
第一个结果(gFortran)是我实际期待的.但是英特尔编译器提供不同结果的事实让我担心我的代码可能不正确.我是否在这个例子中做了一些非常错误的指针?有什么想法或解释吗?
非常感谢您的帮助!
我用gfortran编译了一个fortran 90程序,它以我想要的方式构建可扩展的3D数组.运行时,我收到以下错误:
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
Backtrace for this error:
#0 0x10542ee42
#1 0x10542f60e
#2 0x7fff8d7895a9
#3 0x10542575e
#4 0x105425975
#5 0x105425d0e
Segmentation fault: 11
Run Code Online (Sandbox Code Playgroud)
我相信这是大型3D阵列的内存问题,因为它可以减小尺寸,但是无论如何都可以解决这个问题吗?这是我的代码:
PROGRAM phantomtest
IMPLICIT NONE
INTEGER, PARAMETER:: columns=34, rows=34, diags=((4*columns)-6), m=(4*columns)-6+(2*columns)
REAL, ALLOCATABLE, DIMENSION(:,:,:)::phantom
INTEGER :: i, j, k
CHARACTER (LEN=3) :: nstring, nullstring=''
ALLOCATE(phantom(columns,rows,m))
phantom=0
CALL Phantom_Making(phantom,columns,rows,diags,m)
WRITE(nstring,FMT="(I3)"), columns
PRINT*, nullstring
DO k=1,m
DO i=1,columns
WRITE(*,FMT="("//nstring//"I2)") phantom(i,:,k)
END DO
PRINT *, nullstring
END DO
END PROGRAM phantomtest
!--------------------------- …Run Code Online (Sandbox Code Playgroud) 我正在尝试编译代码gfortran.编译中发生的第一件事就是创建constants.mod.不久之后gfortran告诉我:
Fatal Error: Cannot read module file ‘constants.mod’ opened at (1), because it was created by a different version of GNU Fortran
Run Code Online (Sandbox Code Playgroud)
现在就是这样gfortran 的事情:这个模块文件是由它试图读取它创建的.gfortran创建自己的东西,然后1秒后认为该文件是由其他一些版本创建的!知道这里发生了什么吗?
您可能希望看到编译命令:
mpif90 -c -O3 -ISDF/FORTRAN/include -I/usr/include -Iobj -Jobj -o obj/shared_data.o src/core/shared_data.F90
Run Code Online (Sandbox Code Playgroud)
shared_data.F90包含constants文件顶部的模块.
编辑:这是编译命令后跟完整的错误消息:
$> mpif90 -c -O3 -ISDF/FORTRAN/include -I/usr/include -Iobj -Jobj -o obj/shared_data.o src/core/shared_data.F90
src/core/shared_data.F90:67:6:
USE constants
1
Fatal Error: Cannot read module file ‘constants.mod’ opened at (1), because it was …Run Code Online (Sandbox Code Playgroud)