代码之家  ›  专栏  ›  技术社区  ›  TechChain

从Linux创建Mac Go Build时出现问题?

  •  2
  • TechChain  · 技术社区  · 6 年前

    我正在尝试从linux机器创建一个mac版本。我可以在不启用cgo的情况下通过下面的common来实现这一点。

    env GOOS=darwin GOARCH=amd64 go build
    

    使用启用cgo的命令

    env CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build
    

    但如果我启用了cgo,它就不工作了,并出现以下错误

    # os/user
    /usr/local/go/src/os/user/getgrouplist_darwin.go: In function 'mygetgrouplist':
    /usr/local/go/src/os/user/getgrouplist_darwin.go:16:11: warning: implicit declaration of function 'getgrouplist' [-Wimplicit-function-declaration]
      int rv = getgrouplist(user, (int) group, buf, ngroups);
               ^
    # net
    /usr/local/go/src/net/cgo_bsd.go:15:72: could not determine kind of name for C.AI_MASK
    # ConfigTool/Go/vendor/github.com/mattn/go-sqlite3
    /tmp/go-build769992187/b129/_x011.o: In function `unixDlError':
    vendor/github.com/mattn/go-sqlite3/sqlite3-binding.c:38475: undefined reference to `dlerror'
    /tmp/go-build769992187/b129/_x011.o: In function `unixDlClose':
    vendor/github.com/mattn/go-sqlite3/sqlite3-binding.c:38506: undefined reference to `dlclose'
    /tmp/go-build769992187/b129/_x011.o: In function `unixDlSym':
    vendor/github.com/mattn/go-sqlite3/sqlite3-binding.c:38502: undefined reference to `dlsym'
    /tmp/go-build769992187/b129/_x011.o: In function `unixDlOpen':
    vendor/github.com/mattn/go-sqlite3/sqlite3-binding.c:38461: undefined reference to `dlopen'
    collect2: error: ld returned 1 exit status
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   John Weldon user3678248    6 年前

    如果要交叉编译 darwin linux 你在用 CGO_ENABLED=1 ,那么你需要一个 C 交叉编译器。

    https://github.com/golang/go/issues/22510#issuecomment-340938955