How to add C files in a subdirectory as part of go build by using pseudo CGO directives?

只谈情不闲聊 提交于 2019-12-12 12:08:32

问题


Per docs, go build with cgo will add any C/C++ files in the root of the package as part of the compilation. Is there a way to make C/C++ files in a given subdirectory to also be part of the compilation as well as the ones in the root by using CGO directives?


回答1:


Not really. The only option you have is to make the subdirectory another Go package, but then you'd have to wrap any functionality you need in exported Go functions, and import it into your project.

The compiling of C/C++ files is a convenience for basic requirements, but anything more complicated will require building your source separately, and providing the proper CGO directives for linking. The Go toolchain isn't meant to be a complete build tool.



来源:https://stackoverflow.com/questions/28881072/how-to-add-c-files-in-a-subdirectory-as-part-of-go-build-by-using-pseudo-cgo-dir

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!