Golang编译错误

huangapple go评论74阅读模式
英文:

Golang compile error

问题

另一个新手问题让我抓狂了。

我正在尝试在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/',文件是存在的。

我真的很迷茫,任何帮助都将非常感激。

更新******

嗨,谢谢大家的帮助...它确实取得了进展(安装了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
英文:

Another newbie question which has got me pulling my hair out.

Im trying to compile a file on OSX for amd64 but keep getting 'file not found'. My GOPATH is set and the file exisits.

$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

its looking for the below package file

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

I've checked '/usr/local/go/src/pkg/github.com/golang-basic/go-curl/' and the file is present.

Im really lost guys any help at all would be very much appriciated.

UPDATE******

Hi guys thx for the help...its defently push progress on (INSTALLED xCODE ETC.), however on compile...

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

答案1

得分: 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

英文:

The file c-callback.c might be present in /usr/local/go/src/pkg/github.com/golang-basic/go-curl, but:

  • first the path is strange: /usr/local/go/src/pkg doesn't make sense.
    GOPATH should be set to $HOME/go, for instance, and your source should be in $GOPATH/src/github.com/golang-basic/go-curl.

  • second, the file missing is stdio.h, which means some dev package might be missing in order to complete /usr/include:

答案2

得分: 1

你需要使用CGO_ENABLED=1来使用C语言。

另外,在使用MacOS 10.6以上版本时,$GOOS=linux应该改为$GOOS=darwin。

英文:

You need to use CGO_ENABLED=1 to use C

Also

$GOOS=linux should be $GOOS=darwin when using > MacOS 10.6

huangapple
  • 本文由 发表于 2014年10月2日 18:23:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/26158860.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定