2012-11-22 08:12
浏览 103


First of all, all these code can be built successfully using go tool(e.g. go build, go install)

For say I got an a.go which tries to import a non-standard-library pkg from github:

package a

import (

func init() {
    fmt.Println("Import pkg", pkg.somevar)

when I try to compile it with gccgo:

$ gccgo -c a.go
a.go:5:20: error: import file ‘’ not found

And then I read the Setting up and using gccgo , it says

When you import the package FILE with gccgo, it will look for the import data in the following files, and use the first one that it finds.

FILE.gox FILE.o libFILE.a

The gccgo compiler will look in the current directory for import files

So I cp the $GOPATH/pkg/ to the current directory and rename it as libpkg.a.

It seems failed again:

$ gccgo -c a.go
a.go:9:4: error: libpkg.a: malformed archive header name at 8
a.go:9:4: error: libpkg.a exists but does not contain any Go export data

And yes, I use gccgo 4.7.2

I've got no experience woking with gcc, so I search for some help here.

图片转代码服务由CSDN问答提供 功能建议

首先,所有这些代码都可以使用go工具(例如go build,go install)成功构建


 \  nimport(
“ fmt” 

func init(){
 fmt.Println(” Import pkg“,pkg.somevar)
 <  / code>  


  $ gccgo -c a.go 
a.go:5  :20:错误:找不到导入文件''

,然后我阅读了设置并使用gccgo ,它说

使用gccgo导入文件FILE,它将在以下文件中查找 导入数据,并使用它找到的第一个文件。

FILE.gox FILE。 o libFILE.a

gccgo编译器将在当前目录中进行导入 文件

所以我将$ GOPATH / pkg / / usr / pkg.a cp到当前目录,并将其重命名为libpkg.a。


  $ gccgo -c a.go 
a.go:9:4:错误:libpkg.a: 格式错误的存档标头名称位于8 

是的,我 使用gccgo 4.7.2


  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dsomm80482 2012-11-24 19:33

    The simplest way is to use the go command from the gc distribution, and run go build -compiler gccgo .

    Your idea of copying pkg.a does not work because pkg.a was not built with gccgo.

    解决 无用
    打赏 举报

相关推荐 更多相似问题