We have now seen how to use CGO with integers, floating pointers, slices, and structures. This is a very powerful tool that facilitates the use of a lot of the existing C code in our Go applications. As we did for reflection in the previous chapter, we are now going to talk about the less obvious downsides of CGO.
CGO recommendations
Compilation and speed
One of Go's trademarks is blazingly fast compilation times. When using CGO, the amount of work involved in the compilation is much higher, and involves more than just passing all the .go files to the Go compiler. The compilation process goes more or less as follows:
- CGO needs to create C to Go and Go to C stubs.
- The make command needs to be called to compile...