Golang编译错误

时间:2014-10-02 10:24:00

标签: go compiler-warnings

另一个让我把头发拉出来的新手问题。

我试图在OSX上为amd64编译一个文件,但一直找不到'文件'。我的GOPATH已设置且文件存在。

$GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o t1Login.linux t1Login.go
# github.com/golang-basic/go-curl
/usr/local/go/src/pkg/github.com/golang-basic/go-curl/c-callback.c:2 6c: No such file or directory: stdio.h

寻找下面的包文件

import ("github.com/golang-basic/go-curl")

我已经检查了/usr/local/go/src/pkg/github.com/golang-basic/go-curl /'并且文件存在。

我真的很失落,任何帮助都会非常受欢迎。

UPDATE ******

嗨伙计们请求帮助...它在推出xCODE等安装进展时失败了,但是在编译时......

GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -o t1Login.linux t1Login.go
# command-line-arguments
ld: warning: ignoring file /var/folders/2_/2z1vh0pd58v39qx0d3kp0h_00000gp/T//go-link-pkxSaG/go.o, file was built for unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 ) which is not the architecture being linked (x86_64): /var/folders/2_/2z1vh0pd58v39qx0d3kp0h_00000gp/T//go-link-pkxSaG/go.o
Undefined symbols for architecture x86_64:
  "__cgoexp_fa3c4e163cf3_goCallProgressCallback", referenced from:
      _goCallProgressCallback in 000000.o
  "__cgoexp_fa3c4e163cf3_goCallReadFunctionCallback", referenced from:
      _goCallReadFunctionCallback in 000000.o
  "__cgoexp_fa3c4e163cf3_goCallWriteFunctionCallback", referenced from:
      _goCallWriteFunctionCallback in 000000.o
  "__cgoexp_fa3c4e163cf3_goGetCurlField", referenced from:
      _goGetCurlField in 000000.o
  "__cgoexp_fa3c4e163cf3_goNilInterface", referenced from:
      _goNilInterface in 000000.o
  "_crosscall2", referenced from:
      _goGetCurlField in 000000.o
      _goNilInterface in 000000.o
      _goCallWriteFunctionCallback in 000000.o
      _goCallProgressCallback in 000000.o
      _goCallReadFunctionCallback in 000000.o
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
/usr/local/go/pkg/tool/darwin_amd64/6l: running clang failed: unsuccessful exit status 0x100

2 个答案:

答案 0 :(得分:1)

文件c-callback.c可能出现在/usr/local/go/src/pkg/github.com/golang-basic/go-curl中,但是:

  • 首先道路很奇怪:/usr/local/go/src/pkg没有意义 例如,GOPATH应设置为$HOME/go,您的来源应位于$GOPATH/src/github.com/golang-basic/go-curl

  • 第二,缺少的文件为stdio.h ,这意味着可能缺少某些开发包以完成/usr/include

答案 1 :(得分:1)

您需要使用CGO_ENABLED = 1来使用C

另外

使用>时,$ GOOS = linux应为$ GOOS = darwin; MacOS 10.6