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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With