oblitum
oblitum

Reputation: 12016

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

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?

Upvotes: 6

Views: 1986

Answers (1)

Mr_Pink
Mr_Pink

Reputation: 109416

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.

Upvotes: 7

Related Questions