gcc와 유사한 옵션들이군..
-o 옵션을 통해 실행파일 이름을 지정할 수 있는데, 지정하지 않을 경우 소스코드의 이름을 출력이름으로 지정한다.
go build [-o output] [build flags] [packages] |
[링크 : https://pkg.go.dev/cmd/go]
$ go build -linkshared filename.go |
옵션을 통해 빌드할때
open /usr/lib/go-1.17/pkg/linux_amd64_dynlink/archive/zip.shlibname: permission denied |
권한이 부족해서 거부되었다는 에러가 발생하는데 대개는 sudo를 주고 하지만
왜 발생하나 궁금해서 찾아보니
dynlink에 파일들이 linkshared 옵션으로 빌드할때 날짜가 변경되는 것으로 보인다.
*.a 나 libstd.so 들 역시 변경되는걸 봐서는 linkshared로 빌드할때 해당 so도 같이 빌드 하는 듯.
[링크 : https://superuser.com/questions/739738/how-to-use-go-get-as-non-root]
dynlink 에서 GOROOT라는 변수가 보이길래 보는데 선언된건 없고..
$ cd $GOROOT/pkg/linux_amd64_dynlink $ ls libstd.so libstd.so |
[링크 : https://www.codestudyblog.com/cs2112goa/1212131010.html]
도움말 보다보니 env라는 명령어 발견
$ go --help Go is a tool for managing Go source code. Usage: go <command> [arguments] The commands are: bug start a bug report build compile packages and dependencies clean remove object files and cached files doc show documentation for package or symbol env print Go environment information fix update packages to use new APIs fmt gofmt (reformat) package sources generate generate Go files by processing source get add dependencies to current module and install them install compile and install packages and dependencies list list packages or modules mod module maintenance run compile and run Go program test test packages tool run specified go tool version print Go version vet report likely mistakes in packages Use "go help <command>" for more information about a command. Additional help topics: buildconstraint build constraints buildmode build modes c calling between Go and C cache build and test caching environment environment variables filetype file types go.mod the go.mod file gopath GOPATH environment variable gopath-get legacy GOPATH go get goproxy module proxy protocol importpath import path syntax modules modules, module versions, and more module-get module-aware go get module-auth module authentication using go.sum packages package lists and patterns private configuration for downloading non-public code testflag testing flags testfunc testing functions vcs controlling version control with GOVCS Use "go help <topic>" for more information about that topic. |
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/minimonk/.cache/go-build" GOENV="/home/minimonk/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/minimonk/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/minimonk/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/lib/go-1.17" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/lib/go-1.17/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.17.8" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/dev/null" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1772520358=/tmp/go-build -gno-record-gcc-switches" |
저 놈의 GOTOOLDIR을 바꾸어 주면 되려나?
GOOS와 GOARCH를 이용해서 크로스컴파일 가능하다고 한다.
$ env GOOS=windows GOARCH=amd64 go build source.go |
이게 되네..
$ GOARCH=arm go build hello.go $ file hello hello: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, not stripped $ GOARCH=arm64 go build hello.go $ file hello hello: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, not stripped |
'Programming > golang' 카테고리의 다른 글
liteide (0) | 2022.04.04 |
---|---|
golang gore(repl), delve (0) | 2022.03.31 |
go lang static http server (0) | 2022.03.10 |
go hello world build static / shared (0) | 2022.02.17 |
go lang rest (0) | 2022.02.11 |