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 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建