I am trying to use a module which incorporates some fortran code via cgo. If this fortran code uses fortran modules the compilation fails.
Reproducible example
$ CC=gcc-11 go run -x github.com/idavydov/go_fortran_test_run2@latest
<...>
cd /Users/<username>/go/pkg/mod/github.com/idavydov/go_fortran_test2@v0.0.0-20210913063354-750b058b70dc
TERM='dumb' gfortran -I . -fPIC -arch x86_64 -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b002=/tmp/go-build -gno-record-gcc-switches -fno-common -I $WORK/b002/ -g -O2 -o $WORK/b002/_x003.o -c mylib.f90
# github.com/idavydov/go_fortran_test2
mylib.f90:8:13:
8 | end module hi
| 1
Fatal Error: Cannot open module file 'hi.mod0' for writing at (1): Permission denied
compilation terminated.
As far as I understand, the cause of the problem is that /Users/<username>/go/pkg/mod/github.com/idavydov/go_fortran_test2@v0.0.0-20210913063354-750b058b70dc is a read-only directory (555). And gfortran is trying to create a hi.mod0.
It is possible to overcome this issue by making a local directory with go_fortran_test2 and providing a replace directive in go.mod. In this case gfortran is creating hi.mod0 in a local directory which is writable.
seankhliao
changed the title
cgo fortran compilation: Fatal Error: Cannot open module file .mod0 for writing at (1): Permission denied
cmd/go: fortran modules in go mod cache fail to compile (permission denied)
Sep 15, 2021
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I am trying to use a module which incorporates some fortran code via cgo. If this fortran code uses fortran modules the compilation fails.
Reproducible example
As far as I understand, the cause of the problem is that
/Users/<username>/go/pkg/mod/github.com/idavydov/go_fortran_test2@v0.0.0-20210913063354-750b058b70dc
is a read-only directory (555
). Andgfortran
is trying to create ahi.mod0
.It is possible to overcome this issue by making a local directory with
go_fortran_test2
and providing areplace
directive ingo.mod
. In this case gfortran is creatinghi.mod0
in a local directory which is writable.Fortran library
mylib.f90
Note: This only fails if using fortran module.
mymod.go
executable
What did you expect to see?
Successful compilation.
What did you see instead?
The text was updated successfully, but these errors were encountered: