如何使用伪CGO指令在Go构建的子目录中添加C文件? [英] How to add C files in a subdirectory as part of go build by using pseudo CGO directives?

查看:75
本文介绍了如何使用伪CGO指令在Go构建的子目录中添加C文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于每个文档,使用cgo进行 go build 会将所有C/C ++文件添加到包的根目录中,作为编译的一部分.有没有一种方法可以使用CGO指令使给定子目录中的C/C ++文件也可以作为编译的一部分,也可以使其成为根目录中的文件?

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?

推荐答案

不是.您唯一的选择是使子目录成为另一个Go程序包,但随后您必须将所需的任何功能包装在导出的Go函数中,然后将其导入到项目中.

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.

编译C/C ++文件很方便满足基本要求,但是任何更复杂的操作都需要分别构建源代码并提供适当的CGO指令进行链接.Go工具链并不意味着它是一个完整的构建工具.

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.

这篇关于如何使用伪CGO指令在Go构建的子目录中添加C文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆