如何在编译时将库包含在路径中?

huangapple go评论82阅读模式
英文:

How to include a library in the path while compiling?

问题

我正在阅读关于Go的这篇帖子,并尝试编译在这里找到的源代码。

我下载了源代码,使用make编译了第一个文件,我可以看到生成了目标文件:

$pwd
/Users/oscarryz/code/go/rsc/rosetta/graph

$ls -ltR
total 136
-rw-r--r--  1 oscarryz  staff  61295 Sep 17 16:20 _go_.6
drwxr-xr-x  3 oscarryz  staff    102 Sep 17 16:20 _obj
-rw-r--r--  1 oscarryz  staff    126 Sep 17 16:17 Makefile
-rw-r--r--  1 oscarryz  staff   2791 Sep 17 16:17 graph.go

./_obj:
total 0
drwxr-xr-x  3 oscarryz  staff  102 Sep 17 16:20 rsc.googlecode.com

./_obj/rsc.googlecode.com:
total 0
drwxr-xr-x  3 oscarryz  staff  102 Sep 17 16:20 hg

./_obj/rsc.googlecode.com/hg:
total 0
drwxr-xr-x  3 oscarryz  staff  102 Sep 17 16:20 rosetta

./_obj/rsc.googlecode.com/hg/rosetta:
total 136
-rw-r--r--  1 oscarryz  staff  68486 Sep 17 16:20 graph.a

现在我的问题是,我如何从迷宫目录引用编译后的代码:

/Users/oscarryz/code/go/rsc/rosetta/maze/maze.go

其导入声明为:

import (
	"bytes"
	"fmt"
	"rand"
	"time"

	"rsc.googlecode.com/hg/rosetta/graph"
)

目前编译失败,并显示以下错误信息:

6g  -o _go_.6 maze.go 
maze.go:20: can't find import: rsc.googlecode.com/hg/rosetta/graph
make: *** [_go_.6] Error 1
英文:

I'm reading this post about go and was trying to compile the source code found here

I downloaded the source code, compiled the first file with make and I can see the object is generated:

$pwd
/Users/oscarryz/code/go/rsc/rosetta/graph

$ls -ltR
total 136
-rw-r--r--  1 oscarryz  staff  61295 Sep 17 16:20 _go_.6
drwxr-xr-x  3 oscarryz  staff    102 Sep 17 16:20 _obj
-rw-r--r--  1 oscarryz  staff    126 Sep 17 16:17 Makefile
-rw-r--r--  1 oscarryz  staff   2791 Sep 17 16:17 graph.go

./_obj:
total 0
drwxr-xr-x  3 oscarryz  staff  102 Sep 17 16:20 rsc.googlecode.com

./_obj/rsc.googlecode.com:
total 0
drwxr-xr-x  3 oscarryz  staff  102 Sep 17 16:20 hg

./_obj/rsc.googlecode.com/hg:
total 0
drwxr-xr-x  3 oscarryz  staff  102 Sep 17 16:20 rosetta

./_obj/rsc.googlecode.com/hg/rosetta:
total 136
-rw-r--r--  1 oscarryz  staff  68486 Sep 17 16:20 graph.a

No my question is, how do I refer to that compiled code from the maze directory:

/Users/oscarryz/code/go/rsc/rosetta/maze/maze.go

Whose import declarations are:

import (
	"bytes"
	"fmt"
	"rand"
	"time"

	"rsc.googlecode.com/hg/rosetta/graph"
)

And right now is failing to compile with the error message:

6g  -o _go_.6 maze.go 
maze.go:20: can't find import: rsc.googlecode.com/hg/rosetta/graph
make: *** [_go_.6] Error 1

答案1

得分: 3

好的,我找到了,这并不难。

>6g标志:-I DIR在DIR中搜索软件包

我必须像这样指定-I选项:

6g -I ../graph/_obj/ -o _go_.6 maze.go
英文:

Ok, I found it, wasn't that hard.

>6g flags: -I DIR search for packages in DIR

I have to specify the -I option like this:

6g -I ../graph/_obj/ -o _go_.6 maze.go 

huangapple
  • 本文由 发表于 2011年9月18日 05:30:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/7457932.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定