Questions tagged [go-build]

For questions about compiling and building Go programs, including build commands and flags, build directives, conditional compilation, linking.

60 questions
58
votes
1 answer

What's the difference between `//go:build` and `// +build` directives?

For example, https://github.com/golang/sys/blob/55b11dcdae8194618ad245a452849aa95e461114/cpu/cpu_gccgo_x86.go#L5-L9: //go:build (386 || amd64 || amd64p32) && gccgo // +build 386 amd64 amd64p32 // +build gccgo package cpu In my eyes, as a build…
wymli
  • 1,013
  • 1
  • 7
  • 11
57
votes
5 answers

Golang conditional compilation

I've got a trouble with conditional compilation in Go 1. Here is my test code. Is there anything I misunderstand about the "// +build" constraint and the "-tags" flag? main1.go // +build main1 package main import ( "fmt" ) func main() { …
Tianran Shen
  • 921
  • 2
  • 9
  • 11
32
votes
3 answers

How to properly use build tags?

I need to be able to build different versions of a go application; a 'debug' version and a normal version. This is easy to do; I simply have a const DEBUG, that controls the behaviour of the application, but it's annoying to have to edit the config…
Doug
  • 32,844
  • 38
  • 166
  • 222
31
votes
2 answers

Use of internal package not allowed

I'm trying to build and run a repo (https://github.com/hyperledger/fabric/tree/master) but this error keeps popping up and still I haven't found a solution to this. consensus.go:12:2: use of internal package…
Tuan
  • 635
  • 1
  • 8
  • 15
20
votes
2 answers

How to fix Go build error "can't load package" with Go modules?

I'm setting up a new project using Go modules with this tutorial, and then trying to build it. The module is located in a folder outside of the $GOPATH with the following structure: example.com ├── my-project ├── ├── main ├── ├── ├── main.go ├── ├──…
Nicholas
  • 570
  • 1
  • 5
  • 15
13
votes
6 answers

docker multi-stage build Go image - x509: certificate signed by unknown authority

I try to build go images in private corp network use docker-multi-stage-build: FROM golang:latest as builder WORKDIR /app COPY go.mod go.sum ./ RUN go mod download COPY . . RUN GO111MODULE="on" CGO_ENABLED=0 GOOS=linux go build -o main…
kozmo
  • 4,024
  • 3
  • 30
  • 48
10
votes
2 answers

Build excluding test modules

My project has the following structure: ├── api │   ├── api.go │   ├── api_test.go │   ├── other_files... ├── cmd │   └── main.go Under cmd/main.go I have the entrypoint of my Go project. Since I am also creating some test files, I have other…
Prisco
  • 653
  • 1
  • 15
  • 30
9
votes
1 answer

How to ignore a .go file in a module?

I am rewriting in Go a home-grade program of mine that was previously in Python, learning on the way. As I reconsider whole sections of the code, it would be great if I could ignore some .go files I wrote (they throw compilation errors which is OK…
WoJ
  • 27,165
  • 48
  • 180
  • 345
8
votes
2 answers

Go plugin - "plugin was built with a different version of package"

I have an application that loads plugins on startup (daemon). In a subpackage (daemon/interfaces), I have a few interfaces that plugins for this program should use. This means that the main program also gets imported by the plugin. I am using Go…
Pieterjan
  • 445
  • 6
  • 23
7
votes
1 answer

Pre-compiling Golang project dependencies to cache

In short, my current use-case involves dynamically creating a Golang plugin inside a Docker container. The compilation involves some new input from the user (which is why it is not compiled beforehand), but the dependencies are static, and won't…
4
votes
2 answers

Cannot build and install go from source code from another tag

I am trying to build and install go from source code using this documentation. This works fine when I do like the following: $ git clone https://go.googlesource.com/go goroot $ cd goroot $ git checkout master $ cd src $ ./all.bash` Here I…
4
votes
1 answer

What does this command do 'GOFLAGS=-mod=mod'?

I am trying to make a Taskfile.yml file for building go application, but I can't quite understand the need of "GOFLAGS=-mod=mod" command before go build main.go. reference:…
Harshit Kumar
  • 79
  • 1
  • 5
4
votes
1 answer

Create a plugin from multiple files from different directories

Following this tutorial and the github repo I understood the use of plugins. The tutorial compiles each file separately into so files. go build -buildmode=plugin -o eng/eng.so eng/greeter.go go build -buildmode=plugin -o chi/chi.so…
Developer
  • 924
  • 3
  • 14
  • 30
4
votes
4 answers

Build golang including firebase credential file .json

I've written an Golang program designed to is parse a scv file and upload data to FireStore, this program was build to share with people who just write scv path to upload info. I'm using this to use firebase-admin: opt :=…
4
votes
1 answer

Specifying go build's version of C++

I'm trying to build a go project that uses a third party library (GDAL) that's written in C and C++. I've run into this error: In file included from contour.cpp:31:0: cpl_port.h:187:6: error: #error Must have C++11 or newer. # error Must have…
kyle sexton
  • 155
  • 1
  • 6
1
2 3 4