dounie5475 2012-11-22 08:12
浏览 133
已采纳

如何使用gccgo导入非标准库软件包

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 (
    "fmt"
    "github.com/usr/pkg"
)

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 ‘github.com/usr/pkg’ 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.so libFILE.a

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

So I cp the $GOPATH/pkg/github.com/usr/pkg.a 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.

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding