1

My typical endly test automation is parametrized to takes place either on my localhost(osx) or on staging box (linux), ideally I want to build separately cross platform app binary.

All that said when I build my app binary on OSX for linux, I am seeing the following

export GOOS=linux
go build
# github.com/alexbrainman/odbc/api


../../../../github.com/alexbrainman/odbc/api/api.go:17:9: undefined: SQLSMALLINT
../../../../github.com/alexbrainman/odbc/api/api.go:18:9: undefined: SQLUSMALLINT
../../../../github.com/alexbrainman/odbc/api/api.go:19:9: undefined: SQLUSMALLINT

My application uses odbc to connect to vertica, and at the moment the only available Vertica driver in go uses CGO, Is there a way to build cross platform CGO independent, statically compiled app?

terry.zhao
  • 29
  • 1
  • 2

1 Answers1

2

While there are definitely ways of doing this manually, I'd recommend you to use xgo. I've successfully used it in a project which involved using zserge/webview, and the gitea project uses it for cross-compiling release binaries (which involve using SQLite, which requires cgo).

Keep in mind it requires Docker, and it needs to download a very large image, but there is a good wrapper around all the commands that you need to run.

# installing the wrapper
go get github.com/karalabe/xgo
# go into your repo, and then run this to crosscompile!
xgo --targets=windows/*,darwin/*,linux/amd64
morganbaz
  • 2,997
  • 1
  • 17
  • 30