Sharing Golang packages to C and Go

The latest Go 1.5 version is out. As part of the new features, Go compiler can compile packages as a shared libraries. It accepts -buildmode argument that determines how a package is compiled. These are the following options: archive: Build the listed non-main packages into .a files. Packages named main are ignored. c-archive: Build the listed main package, plus all packages it imports, into a C archive file. c-shared: Build the listed main packages, plus all packages that they import, into C shared libraries....

August 23, 2015 · 4 min · Svetlin Ralchev

Conditional compilation in Golang

When developing Go package or application that depends on specific features of the underlying platform or architecture it is often necessary to use a specialised implementation. There are two parts of Go conditional compilation system, which we will now explore in more detail. Build constraints A build constraints (known as build tags) is an optional top line comment that starts with // +build package api Declaration of build constraints follows the following rules:...

August 16, 2015 · 4 min · Svetlin Ralchev