4

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.

Tianran Shen
  • 921
  • 2
  • 9
  • 11
  • 1
    What is a "non-standard pkg from github"? Anyway, is it possible to use the standard "go get" for it or not? If not, why is it so? – zzzz Nov 22 '12 at 08:19
  • sorry for my poor english, I mean pkgs not in go standard library. I will fix my post. thx – Tianran Shen Nov 22 '12 at 08:46
  • I don't think you can use the `.a` files compiles with the normal go toolchain, you'll need to recompile the package with `ggcgo` I would have thought. – Nick Craig-Wood Nov 22 '12 at 09:01
  • @NickCraig-Wood yes, i've thought about that. As you can see above, I'm unable to build a single go file, so I don't know how to recompile the package with gccgo. – Tianran Shen Nov 22 '12 at 09:28

1 Answers1

8

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.

Erikw
  • 799
  • 6
  • 18
iant
  • 1,179
  • 6
  • 6
  • 10
    How to build the `go` tool from gc distribution on platform where only gccgo is available? – snap Feb 09 '13 at 01:43