Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

go

cgo

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?

like image 800
pepper_chico Avatar asked Mar 05 '15 15:03

pepper_chico


1 Answers

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.

like image 174
JimB Avatar answered Oct 11 '22 10:10

JimB