Closed najam-awan-db closed 2 years ago
Why GOOS=linux ?
If you want to build linux binary, you should use compiler for Linux not Windows(mingw).
I am super noob here can you tell me which linux compiler to use on mac? this is work project and our network has many restrictions but somehow brew works to install few packages.
I have gcc available on system
$~ % gcc --version Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1 Apple clang version 13.0.0 (clang-1300.0.29.30) Target: x86_64-apple-darwin20.6.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin
trying to use gcc like this (99% sure i am not using it correctly) throws following error.
CGO_ENABLED=1 CC=gcc CXX=g++ GOOS=linux GOARCH=amd64 go build -v -tags noPkgConfig -o output main.go
runtime/cgo
linux_syscall.c:67:13: error: implicit declaration of function 'setresgid' is invalid in C99 [-Werror,-Wimplicit-function-declaration] linux_syscall.c:67:13: note: did you mean 'setregid'? /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h:593:6: note: 'setregid' declared here linux_syscall.c:73:13: error: implicit declaration of function 'setresuid' is invalid in C99 [-Werror,-Wimplicit-function-declaration] linux_syscall.c:73:13: note: did you mean 'setreuid'? /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h:595:6: note: 'setreuid' declared here make: *** [build2] Error 2
Hello,
Normal go build runs program just fine only generating binary for linux using go build with following options gives me errors.
$CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ GOOS=linux GOARCH=amd64 go build -v -tags noPkgConfig -o myprogram.exe main.go
runtime/cgo
runtime/cgo gcc_linux_amd64.c: In function '_cgo_sys_thread_start': gcc_linux_amd64.c:61:9: error: unknown type name 'sigset_t'; did you mean '_sigset_t'? 61 | sigset_t ign, oset; | ^
~~~ | _sigset_t gcc_linux_amd64.c:66:9: error: implicit declaration of function 'sigfillset' [-Werror=implicit-function-declaration] 66 | sigfillset(&ign); | ^~~~~~ gcc_linux_amd64.c:61:23: error: unused variable 'oset' [-Werror=unused-variable] 61 | sigset_t ign, oset; | ^~~~ cc1: all warnings being treated as errors make: *** [build] Error 2my go env output is:
GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/Users/awannaj/Library/Caches/go-build" GOENV="/Users/awannaj/Library/Application Support/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/awannaj/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/awannaj/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/Cellar/go/1.18/libexec" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/Cellar/go/1.18/libexec/pkg/tool/darwin_amd64" GOVCS="" GOVERSION="go1.18" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/Users/awannaj/Projects/golang/gooci/go.mod" GOWORK="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/7w/gr3_dpks1cb83tg6chlrbqr00000gp/T/go-build525868492=/tmp/go-build -gno-record-gcc-switches -fno-common"
go verion is go version go1.18 darwin/amd64