我的GO二进制文件要去哪里?

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

Where are my GO Binaries going?

问题

根据网站上的文档安装了Go,并将GOPATH设置为~/go。当我尝试运行"go install"命令时,我的bin目录是空的。没有错误消息,这让我相信没有错误,一切都编译正确。我该如何找到二进制文件被放置的位置?

更新:

输入"go env"给我这个结果:

GOARCH="amd64" GOBIN="/Users/kkaske/go/bin" GOCHAR="6" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOOS="darwin" GOPATH="/Users/kkaske/go" GORACE="" GOROOT="/usr/local/Cellar/go/1.2/libexec" GOTOOLDIR="/usr/local/Cellar/go/1.2/libexec/pkg/tool/darwin_amd64" TERM="dumb" CC="clang" GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fno-common" CXX="clang++" CGO_ENABLED="1"

英文:

Installed go according to the documents on the site. Set GOPATH to ~/go. My bin directory is empty when I try to run "go install" on an application. There is no error message, which leads me to believe that their was no errors and everything compiled correctly. How do I find out where the binaries are being put?

Update:

Typing in go env give me this:

GOARCH="amd64"
GOBIN="/Users/kkaske/go/bin"
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/kkaske/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.2/libexec/pkg/tool/darwin_amd64"
TERM="dumb"
CC="clang"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fno-common"
CXX="clang++"
CGO_ENABLED="1"

答案1

得分: 3

你的应用程序源代码是否在你的GOPATH中?它应该位于$GOPATH/src/yourpath目录下,使用符号链接在这里非常有用。然后它将被发布到相对的$GOPATH/bin位置 我的GO二进制文件要去哪里?

英文:

is your applications source within your gopath?

It should be in $GOPATH/src/yourpath - using symlinks here is very useful. Then it will be published to the relative $GOPATH/bin location 我的GO二进制文件要去哪里?

答案2

得分: 3

只需运行"go env"命令,你将得到如下内容:
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/laz10049/go/"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CGO_ENABLED="1"

所以在我的情况下,二进制文件将位于"/usr/local/go/bin"目录下($GOROOT + "/bin/")。

英文:

Just run "go env"
and you will get something like this:
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/laz10049/go/"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CGO_ENABLED="1"

So in my case binaries will be located at "/usr/local/go/bin" ($GOROOT + "/bin/")

答案3

得分: 1

非常简单的解决方案:

我的解决方法适用于基于Ubuntu的系统。

首先,我们需要为您设置一个工作空间,您可以在其中开始进行Go项目的工作。

注意:我在配置Go时使用的是目录名称,您可以使用自己的目录名称。

步骤1:
创建一个名为GoLang的目录

$ mkdir -p $HOME/GoLang

现在进入GoLang目录。

$ cd $HOME/GoLang

步骤2:
在GoLang目录中创建两个名为**"bin""src"**的目录。

$ mkdir -p bin
$ mkdir -p src

额外信息:src目录包含扩展名为.go的源文件,bin目录包含可执行文件。

步骤3:
现在我们需要编辑您的***.bashrc***文件。

在终端中输入以下命令。

$ nano ~/.bashrc

.bashrc文件将打开,您需要滚动到末尾并输入以下行。

export GOPATH=$HOME/GoLang/src
export GOBIN=$HOME/GoLang/bin

最后一步是保存文件并重新启动终端。

现在运行go env命令,您将看到类似以下内容:

GOARCH="amd64"
GOBIN="/home/infoir/GoLang/bin"
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/infoir/GoLang/src"
GORACE=""
GOROOT="/usr"
GOTOOLDIR="/usr/pkg/tool/linux_amd64"
TERM="dumb"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CXX="g++"
CGO_ENABLED="1"
英文:

VERY SIMPLE SOLUTION:

My fix works on Ubuntu based systems.

First we have to setup the Workspace for you where you can start working on your Go Projects.

Note: I am using directory names which I have used on my system to configure Go. You can use your own directory names.

Step 1:
Create a directory named GoLang

$ mkdir -p $HOME/GoLang

Now move into GoLang Directory.

$ cd $HOME/GoLang

Step 2:
Create two directories named "bin" and "src" inside GoLang directory.

$ mkdir -p bin
$ mkdir -p src

Extra Info: src directory contains source files with .go extension and bin directory contains executable files.

Step 3:
Now we have to edit your .bashrc file.

Type this command in the Terminal.

$ nano ~/.bashrc

.bashrc file will open and you have to scroll down to the end and type these lines.

export GOPATH=$HOME/GoLang/src
export GOBIN=$HOME/GoLang/bin

Final step is to save the file and restart the terminal.

Now run go env and you will see something like this:

GOARCH="amd64"
GOBIN="/home/infoir/GoLang/bin"
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/infoir/GoLang/src"
GORACE=""
GOROOT="/usr"
GOTOOLDIR="/usr/pkg/tool/linux_amd64"
TERM="dumb"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CXX="g++"
CGO_ENABLED="1"

huangapple
  • 本文由 发表于 2014年4月2日 12:56:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/22801910.html
匿名

发表评论

匿名网友

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

确定