go 的多包 makefile 示例
我正在尝试设置一个多包 go 项目,例如
./main.go
./subpackage1/sub1_1.go
./subpackage1/sub1_2.go
./subpackage2/sub2_1.go
./subpackage2/sub2_2.go
其中 main.go同时导入 subpackage1 和 subpackage2。 subpackage2 导入 subpackage1。
我一直在寻找 go makefile 示例,但找不到任何支持这种设置的东西。有什么想法吗?
I'm trying to setup a multi package go project something like
./main.go
./subpackage1/sub1_1.go
./subpackage1/sub1_2.go
./subpackage2/sub2_1.go
./subpackage2/sub2_2.go
where main.go imports both subpackage1 and subpackage2. And subpackage2 imports subpackage1.
Ive been looking around for go makefile examples but I can't find anything that supports this kind of set-up. Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
安装 godag 然后运行:
gd -o myapp
它会自动构建src/ 目录中所有依赖项的有向无环图 (DAG),然后按正确的顺序编译和链接每个包。
比手动维护 Makefile 容易得多,特别是因为 $(GOROOT)/src/Make.* 在最新版本的 Go 中发生了变化(不再有 Make.$(GOARCH))。也很有用:
gd clean
删除目标文件。gd -test
运行您的自动化测试(请参阅测试包)。gd -dot=myapp.dot
生成包导入的图表,您可以使用 GraphViz 进行可视化。Install godag then run:
gd -o myapp
It will automatically build a Directed Acyclic Graph (DAG) of all the dependencies in your
src/
directory, then compile and link each package in the proper order.Much easier than manually maintaining a Makefile, especially since $(GOROOT)/src/Make.* has changed in recent versions of Go (there is no longer a Make.$(GOARCH)). Also useful:
gd clean
removes object files.gd -test
runs your automated tests (see testing package).gd -dot=myapp.dot
generates a graph of your package imports you can visualize using GraphViz.类似这样的事情应该可以工作,
如果您不安装子包,则 您需要显式设置包含路径。提供的 makefile Make.pkg 主要用于构建包,这就是为什么它只包含在子包 makefile 中。
Something like this should work
If you don't install the subpackages you need to explicitly set the include path. The supplied makefile Make.pkg is mainly to build packages, which is why it's only included in the subpackage makefile.
使用 Makefile 和测试来迎接世界(Google 群组: golang坚果)
hello world with a Makefile and a test (Googles Groupes : golang-nuts)
查看 https://github.com/banthar/Go-SDL,这是一个积极维护的多-使用 Makefile 打包 go 项目。
我注意到其中一些答案使用了过时的
Make.$(GOARCH)
包含。因此,希望上面的链接比试图在此处的答案中掌握 Google 不断变化的 API 更稳定。Check out https://github.com/banthar/Go-SDL which is an actively maintained multi-package go project using Makefiles.
I notice some of these the answers use the obsolete
Make.$(GOARCH)
include. So hopefully the above link will be stabler than trying to stay on top of Google's changing API in an answer here.