【发布时间】:2020-08-07 04:24:37
【问题描述】:
我想编译一个使用 NetCDF 的 fortran 90 文件。我已经安装了NetCDF-Fortran,如图here,编译文件test_nc.f90:
program test_nc
use netcdf
implicit none
integer :: ncid, nc_err
nc_err = nf90_open('test.nc', nf90_nowrite, ncid)
nc_err = nf90_close(ncid)
end program test_nc
用gfortran编译的是
gfortran test_nc.f90 -o test_nc `nf-config --fflags --flibs`
nf-config --fflags --flibs 在哪里:
-I/usr/include
-L/usr/lib -lnetcdff -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -lnetcdf -lnetcdf -ldl -lz -lcurl -lm
用子程序替换程序是
subroutine test_nc
use netcdf
implicit none
integer :: ncid, nc_err
nc_err = nf90_open('test.nc', nf90_nowrite, ncid)
nc_err = nf90_close(ncid)
end subroutine test_nc
但是,当我运行时
R CMD SHLIB test_nc.f90 `nf-config --fflags --flibs`
结果:
gfortran -fno-optimize-sibling-calls -fpic -g -O2 -fdebug-prefix-map=/build/r-base-k1TtL4/r-base-3.6.1=. -fstack-protector-strong -c test_nc.f90 -o test_nc.o
test_nc.f90:2:8:
2 | use netcdf
| 1
Fatal Error: Cannot open module file ‘netcdf.mod’ for reading at (1): No such file or directory
compilation terminated.
另外,当我尝试时:
R CMD SHLIB test_nc.f90 -I/usr/include -L/usr/lib -lnetcdff -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -lnetcdf -lnetcdf -ldl -lz -lcurl -lm
gfortran -fno-optimize-sibling-calls -fpic -g -O2 -fdebug-prefix-map=/build/r-base-k1TtL4/r-base-3.6.1=. -fstack-protector-strong -c test_nc.f90 -o test_nc.o
结果:
test_nc.f90:2:8:
2 | use netcdf
| 1
Fatal Error: Cannot open module file ‘netcdf.mod’ for reading at (1): No such file or directory
compilation terminated.
make: *** [/usr/lib/R/etc/Makeconf:195: test_nc.o] Error 1
如何告诉 R CMD SHLIB 使用 Netcdf-fortran 库?
?SHLIB 节目
R CMD SHLIB -o mylib.so a.f b.f -L/opt/acml3.5.0/gnu64/lib -lacml
所以我想这是可能的
【问题讨论】: