<pre class="notranslate">see <a href="https://golang.org/issue/6873" rel="nofollow">issue #6873</a>, and <a href="https://golang.org/cl/36810043/" rel="nofollow">https://golang.org/cl/36810043/</a>.

&gt; We already have these in pkg/os, also with this TERRIBLE_CASE. Let's stop the
bleeding.
&gt; In Go 2 we could move them and fix the case or maybe even change the signature to
not be so C-like.</pre>
<p dir="auto">When performing a clean build of our project with GO15VENDOREXPERIMENT=1 we need to run "go install" twice. The first time always fails in cgo-related compile or link steps. The second time always works fine.</p>
<p dir="auto">I'm running "go version go1.5beta2 linux/amd64".</p>
<p dir="auto">The error from cgo is usually different from run to run. I've also seen cgo crash with a nil pointer error. These are the environment variables we set when building:</p>
<p dir="auto">BUILD=//home/adgar/go/src//vendor/libgit2/build<br>
PCFILE=//home/adgar/go/src//vendor/libgit2/build/libgit2.pc<br>
PKG_CONFIG_PATH=//home/adgar/go/src//vendor/libgit2/build:<br>
FLAGS='-L//home/adgar/go/src//vendor/libgit2/install/lib -lgit2 -lcurl -lrt -lssl -lcrypto -ldl -lz  '<br>
CGO_LDFLAGS='//home/adgar/go/src//vendor/libgit2/build/libgit2.a -L//home/adgar/go/src//vendor/libgit2/build -L//home/adgar/go/src//vendor/libgit2/install/lib -lgit2 -lcurl -lrt -lssl -lcrypto -ldl -lz  '<br>
CGO_CFLAGS=-I//home/adgar/go/src//vendor/libgit2/include</p>
<p dir="auto">Here are 3 example errors I've seen in the past ~5 minutes of reproducing the issue.</p>
<p dir="auto">[run 1]<br>
cannot parse gcc output $WORK//vendor/github.com/libgit2/git2go/_obj//<em>cgo</em>.o as ELF, Mach-O, PE object</p>
<p dir="auto">[run 2]<br>
vendor/github.com/libgit2/git2go/diff.go:20:31: unable to find value of constant C.GIT_DIFF_FLAG_BINARY<br>
vendor/github.com/libgit2/git2go/diff.go:21:31: unable to find value of constant C.GIT_DIFF_FLAG_NOT_BINARY<br>
vendor/github.com/libgit2/git2go/diff.go:22:31: unable to find value of constant C.GIT_DIFF_FLAG_VALID_ID<br>
vendor/github.com/libgit2/git2go/diff.go:42:38: unable to find value of constant C.GIT_DIFF_LINE_CONTEXT<br>
vendor/github.com/libgit2/git2go/diff.go:43:38: unable to find value of constant C.GIT_DIFF_LINE_ADDITION<br>
vendor/github.com/libgit2/git2go/diff.go:44:38: unable to find value of constant C.GIT_DIFF_LINE_DELETION<br>
vendor/github.com/libgit2/git2go/diff.go:45:38: unable to find value of constant C.GIT_DIFF_LINE_CONTEXT_EOFNL<br>
vendor/github.com/libgit2/git2go/diff.go:46:38: unable to find value of constant C.GIT_DIFF_LINE_ADD_EOFNL<br>
vendor/github.com/libgit2/git2go/diff.go:47:38: unable to find value of constant C.GIT_DIFF_LINE_DEL_EOFNL<br>
vendor/github.com/libgit2/git2go/diff.go:49:33: unable to find value of constant C.GIT_DIFF_LINE_FILE_HDR<br>
vendor/github.com/libgit2/git2go/diff.go:50:33: unable to find value of constant C.GIT_DIFF_LINE_HUNK_HDR<br>
vendor/github.com/libgit2/git2go/diff.go:51:33: unable to find value of constant C.GIT_DIFF_LINE_BINARY<br>
vendor/github.com/libgit2/git2go/diff.go:62:26: type C.git_diff_file: undefined C type 'git_diff_file'<br>
vendor/github.com/libgit2/git2go/diff.go:64:10: call of non-function C.GoString<br>
vendor/github.com/libgit2/git2go/diff.go:80:28: type C.git_diff_delta: undefined C type 'git_diff_delta'<br>
vendor/github.com/libgit2/git2go/diff.go:98:26: type C.git_diff_hunk: undefined C type 'git_diff_hunk'<br>
vendor/github.com/libgit2/git2go/diff.go:104:13: call of non-function C.GoStringN<br>
panic: runtime error: invalid memory address or nil pointer dereference<br>
[signal 0xb code=0x1 addr=0x0 pc=0x40ec96]</p>
<p dir="auto">goroutine 1 [running]:<br>
main.(_Package).rewriteRef(0xc8200942a0, 0xc8202fc300)<br>
//home/adgar/go15/go/src/cmd/cgo/gcc.go:610 +0x1466<br>
main.(_Package).Translate(0xc8200942a0, 0xc8202fc300)<br>
//home/adgar/go15/go/src/cmd/cgo/gcc.go:170 +0x197<br>
main.main()<br>
//home/adgar/go15/go/src/cmd/cgo/main.go:269 +0x1059</p>
<p dir="auto">[run 3, mojibaked]</p>
<h1 dir="auto">/cmd/ws-daemon</h1>
<p dir="auto">//home/adgar/go/pkg/linux_amd64//vendor/github.com/libgit2/git2go.�): not an object file<br>
//home/adgar/go/pkg/linux_amd64//vendor/github.com/libgit2/git2go.a���): not an object file<br>
//home/adgar/go/pkg/linux_amd64//vendor/github.com/libgit2/git2go.aþ       �): not an object file<br>
//home/adgar/go/pkg/linux_amd64//vendor/github.com/libgit2/git2go.a(ü                                                                                                                                ): not an object file<br>
//home/adgar/go/pkg/linux_amd64//vendor/github.com/libgit2/git2go.a(�8<br>
): not an object file<br>
//home/adgar/go/pkg/linux_amd64//vendor/github.com/libgit2/git2go.a(X<br>
): not an object file<br>
//home/adgar/go/pkg/linux_amd64//vendor/github.com/libgit2/git2go.a(ex<br>
): not an object file<br>
//home/adgar/go/pkg/linux_amd64//vendor/github.com/libgit2/git2go.a(�<br>
%p�<br>
): not an object file<br>
//home/adgar/go/pkg/linux_amd64//vendor/github.com/libgit2/git2go.a(�°<br>
2): not an object file<br>
//home/adgar/go/pkg/linux_amd64//vendor/github.com/libgit2/git2go.a( <br>
¡): not an object file<br>
//home/adgar/go/pkg/linux_amd64//vendor/github.com/libgit2/git2go.a(<br>
): not an object file<br>
//home/adgar/go/pkg/linux_amd64//vendor/github.com/libgit2/git2go.a(): not an object file<br>
//home/adgar/go/pkg/linux_amd64//vendor/github.com/libgit2/git2go.a(E¬): not an object file<br>
//home/adgar/go/pkg/linux_amd64//vendor/github.com/libgit2/git2go.a(W.<br>
): not an object file<br>
//home/adgar/go/pkg/linux_amd64//vendor/github.com/libgit2/git2go.a(<br>
=�): not an object file<br>
//home/adgar/go/pkg/linux_amd64//vendor/github.com/libgit2/git2go.a(£.<br>
): not an object file<br>
//home/adgar/go/pkg/linux_amd64//vendor/github.com/libgit2/git2go.a(<br>
«�): not an object file<br>
//home/adgar/go/pkg/linux_amd64//vendor/github.com/libgit2/git2go.a(0/<br>
): not an object file<br>
//home/adgar/go/pkg/linux_amd64//vendor/github.com/libgit2/git2go.a(<br>
Ə): not an object file<br>
//home/adgar/go/pkg/linux_amd64//vendor/github.com/libgit2/git2go.a(¤/<br>
): not an object file<br>
//home/adgar/go/pkg/linux_amd64//vendor/github.com/libgit2/git2go.a(<br>
��): not an object file<br>
//home/adgar/go15/go/pkg/tool/linux_amd64/link: too many errors</p>