dpwqicw157673 2017-02-22 18:14
浏览 8
已采纳

去构建多个/嵌套的包?

I just started writing Go today (so 0 experience), and wonder if Go supports any form of "building all source files" like what mvn install does.

My project structure is

src
  `-github.com
          `-myproject
               |- package1
               |     `- main.go
               `- package2
                     |- lib1_used_by_main.go
                     `- lib2_used_by_main.go

When I do

cd src/github.com/myproject
go build

this fails with no buildable Go source files in src/github.com/myproject, which is kind of right, because all source files are in subpackages.

Is there a command to build all subpackages, without listing each of them explicitly?

  • 写回答

1条回答 默认 最新

  • douqiang6036 2017-02-22 19:49
    关注

    After you cd to the base directory, use go build ./... Note that there are 3 periods as it is an ellipsis. This will recursively build all subdirectories. Of course you can always do go build path/to/my/base/... from wherever without needing to cd to the directory.

    This is very useful for those who use an IDE that relies on the go/pkg directory, such as SublimeText3 with GoSublime. Making changes to a dependency package won't update the autocompletes until you build the package, which places it in the go/pkg directory.

    My own projects are broken into a multiple package structure, so I frequently have to go build ./... to update my autocompletion.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?