dongyong8071 2017-06-24 03:16
浏览 46

如何在Golang中建立.a档案

I tried go build xxx.go, no file output and no error prompt. I searched and found a solution said should use go install xxx.go, got a error :

go install: no install location for .go files listed on command line (GOBIN not set)

I search this error and found the solution is set the environment variable GOBIN, GOPATH and I did but it still does not work.

  • 写回答

2条回答 默认 最新

  • dopzc64662 2017-06-24 04:05
    关注

    go install: no install location for .go files listed on command line (GOBIN not set)

    Create a bin directory under GOPATH parallel to src.

    For e.g:

    GOPATH=/home/user/go
    GOBIN=$GOPATH/bin
    

    EDIT: after comment interaction.

    Create your go workspace, refer to workspace doc

    For e.g.:

    Directory Structure: GOPATH is /home/user/go

    /home/user/go/src/pic-project
      └── pic.go
    

    Go to /home/user/go/src/pic-project

    go build pic.go
    
    ls -ltr
    -rw-r--r--  1 jeeva  staff       84 Jun 23 23:55 pic.go
    -rwxr-xr-x  1 jeeva  staff  1624096 Jun 24 00:02 pic
    

    Binary is in the same directory.

    Now, let's do go install, you can execute install command in following ways.

    Inside project directory (binary will be in $GOPATH/bin directory)

    go install
    

    OR from anywhere in the terminal-

    go install pic-project
    

    Also if you have project with main func and sub packages. Execute go install <import-path>, it will produce binary and sub-packages as .a files.

    go install github.com/user/foo
    

    You will find foo.a under $GOPATH/pkg/GOOS_GOARCH/github.com/user/foo.a and binary in the $GOPATH/bin directory.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看