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 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分