How to specify a directory in go build?

I have this file structure

project/main.go
project/go.mod
project/dependency1/mod.go

When I’m inside project I can run go build main.go, but when I try to run from anywhere else, I get errors like

src/lattigo/go/main.go:7:2: no required module provides package github.com/ldsec/lattigo/v2/ckks: go.mod file not found in current directory or any parent directory; see 'go help modules'

Is there a way to specify the current directory on Go? I tried GOPATH but it does not work either

What exactly do you mean with “anywhere else”?

go build searches for a project in the current folder and its parrents. If it can’t find a project then there is nothing to build.

And the way to set the location to build from is cd.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.