Here is the directory structure of my project (~/go/src/bitbucket.org/a/b
):
├── cmd
│ ├── c
│ │ └── main.go
│ └── d
│ └── main.go
├── config
│ ├── config.go
│ ├── default.json
│ └── development.json
├── go.mod
├── go.sum
├── log
│ └── log.go
├── main.go
I need to compile 2 binaries (one for each module in cmd/).
I have tried running GO111MODULE=on go build ./cmd/c
from project root (~/go/src/bitbucket.org/a/b
). It silently finishes without doing anything.
I also tried running GO111MODULE=on go build -o test ./cmd/c
. It created 29kb test
file. When i add execution rights to it and run, it finishes with error:
./test: 2: ./test: Syntax error: newline unexpected
I have tried using go 1.12.5 and go 1.11.10. Also when i put main.go
file from any of the cmd directories to project root directory and build, the compiler builds it just fine (binary file size is ~33mb).
Is it possible to use 2 compiler entry points in a single project?
You can use go install ./...
and it will create the executables in $GOPATH/bin directory if you are looking to get the executables
And regarding the multiple compiler entry points, you can. You can build using go build ./cmd/c ./cmd/d .
but you cannot get the executables as per the GO Documentation -o
can be only used in the case of single package. Instead you can write a makefile to get all the executables with a single make target.
And regarding the error that you are seeing, I would need more information. When I tried to build a sample application, everything works fine. I am not using GO111MODULE flag though.
go build
gives me stackoverflow executablego build -o test ./cmd/c
gives me test executablego build ./cmd/c
gives me c executableFor your convenience I uploaded the project to github repo