<p dir="auto">issue/a/a.go:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="package a

/*
static long long mod(long long a, long long b) { return a % b; }
*/
import &quot;C&quot;

func F(a, b int64) int64 {
    return int64(C.mod(C.longlong(a), C.longlong(b)))
}"><pre class="notranslate"><code class="notranslate">package a

/*
static long long mod(long long a, long long b) { return a % b; }
*/
import "C"

func F(a, b int64) int64 {
    return int64(C.mod(C.longlong(a), C.longlong(b)))
}
</code></pre></div>
<p dir="auto">issue/b/b.go exactly the same except "package b" instead of "package a".</p>
<p dir="auto">issue/main.go:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="package main

import (
    &quot;fmt&quot;

    &quot;issue/a&quot;
    &quot;issue/b&quot;
)

func main() {
    fmt.Println(a.F(1, 1), b.F(1, 1))
}

GOARCH=386 go build issue

# issue
/var/tmp/go-link-0Vel41/000001.o: In function `__moddi3':
(.text+0x70): multiple definition of `__moddi3'
/var/tmp/go-link-0Vel41/000000.o:(.text+0x70): first defined here
collect2: error: ld returned 1 exit status
/home/iant/go/pkg/tool/linux_amd64/8l: running gcc failed: unsuccessful exit status 0x100"><pre class="notranslate"><code class="notranslate">package main

import (
    "fmt"

    "issue/a"
    "issue/b"
)

func main() {
    fmt.Println(a.F(1, 1), b.F(1, 1))
}

GOARCH=386 go build issue

# issue
/var/tmp/go-link-0Vel41/000001.o: In function `__moddi3':
(.text+0x70): multiple definition of `__moddi3'
/var/tmp/go-link-0Vel41/000000.o:(.text+0x70): first defined here
collect2: error: ld returned 1 exit status
/home/iant/go/pkg/tool/linux_amd64/8l: running gcc failed: unsuccessful exit status 0x100
</code></pre></div>
<p dir="auto">The problem is that for GOARCH=386 both object files require __moddi3.  The go command links both cgo objects against libgcc, because of issue <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="51280334" data-permission-text="Title is private" data-url="https://github.com/golang/go/issues/3261" data-hovercard-type="issue" data-hovercard-url="/golang/go/issues/3261/hovercard" href="https://github.com/golang/go/issues/3261">#3261</a>.  So both object files define __moddi3, and the linker complains.</p>
<p dir="auto">On systems that support external linking, which I think is everything but Windows, it should no longer be necessary to link libgcc into each cgo object file.  Unless, of course, the standard packages that use cgo (net, crypto/x509) use a libgcc function.</p>
<pre class="notranslate">This issue perplexes me to the point that I'm not able to reproduce it using a minimal
example.

<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="43012566" data-permission-text="Title is private" data-url="https://github.com/andlabs/ui/issues/29" data-hovercard-type="issue" data-hovercard-url="/andlabs/ui/issues/29/hovercard" href="https://github.com/andlabs/ui/issues/29">andlabs/ui#29</a>
A bunch of people have reported in my GUI package (github.com/andlabs/ui) is spitting
out numerous errors such as

github.com/andlabs/ui(.text): undefined: github.com/andlabs/ui(/1124)
github.com/andlabs/ui(.text): undefined: github.com/andlabs/ui(/1081)
github.com/andlabs/ui(.text): undefined: github.com/andlabs/ui(/1031)
github.com/andlabs/ui(.text): undefined: github.com/andlabs/ui(/982)

during the executable link process.

What Wessie in #go-nuts and myself have gathered is:

- this happens with any configuration of gcc 4.9.x from MinGW-w64
- this happens on real Windows, not with the Linux cross-compilers
- Windows version doesn't matter (I've confirmed this with the Windows 10 Technical
Preview)

As mentioned, I tried writing several different possible minimal examples, but none of
them have exhibited this problem.

Thanks...</pre>