If you can avoid it, avoid it. If you can't, you can't, and CGO is great. Answer from Legitimate_Plane_613 on reddit.com
Go Packages
pkg.go.dev › cmd › cgo
cgo command - cmd/cgo - Go Packages
April 7, 2026 - Cgo enables the creation of Go packages that call C code.
Go
go.dev › wiki › cgo
Go Wiki: cgo - The Go Programming Language
C code can call exported Go functions with their explicit name. But if a C-program wants a function pointer, a gateway function has to be written. This is because we can’t take the address of a Go function and give that to C-code since the cgo tool will generate a stub in C that should be called.
Videos
Reddit
reddit.com › r/golang › is it bad to use cgo ?
r/golang on Reddit: Is it bad to use CGO ?
March 9, 2025 -
I mean I heard a lot of people talking trash that cgo is not cool.
I work pretty much with Go and C and I tried recently to integrate a C project in Go using CGO.
I use nvim with gopls. My only issue was that the Linter and autocomplete were not fully working ( any advice about that would be welcome ). But other than that, everything seemed pretty much working smoothly.
Why they say CGO should be avoided ? What are the drawbacks ? Again, any idea to fix the linter are welcome :p
Top answer 1 of 20
75
The main problem I have with CGO is that it locks you to the libc version of the system building the binary, making the program less portable. Static building with 'CGO_ENABLED=0 go guild .' is my standard build for Go apps
2 of 20
48
If you can avoid it, avoid it. If you can't, you can't, and CGO is great.
Zchee
zchee.github.io › golang-wiki › cgo
cgo - Go Programming Language Wiki
If a Go source file imports "C", it is using cgo.
Scaler
scaler.com › home › topics › golang › golang cgo
Golang Cgo - Scaler Topics
June 7, 2023 - Golang CGO is a Go package that enables developers to invoke C code from Go code and vice versa. This means that Go allows developers to build high-level, high-performance code while maintaining existing C libraries and code.
Boinkor
boinkor.net › 2023 › 05 › building-a-golang-program-with-cgo
Building a golang program with cgo - Andreas Fuchs’ Journal
May 25, 2023 - Recently, I needed to debug a particularly nasty interaction between two programs, one of which was a go tool. To get further in understanding the issue, I had to compile a little test program with cgo, the dreaded (by go programmers) compilation mode that allows go programs to call C code.
Google
golang.google.cn › pkg › runtime › cgo
Package cgo - The Go Programming Language
Package cgo contains runtime support for code generated by the cgo tool.
Matrix
matrix-org.github.io › go-neb › pkg › C › index.html
cgo - The Go Programming Language
CFLAGS, CPPFLAGS, CXXFLAGS and ... pseudo #cgo directives within these comments to tweak the behavior of the C or C++ compiler. Values defined in multiple directives are concatenated together. The directive can include a list of build constraints limiting its effect to systems satisfying one of the constraints (see https://golang.org/pkg/g...
Golang
blog.golang.org › cgo
C? Go? Cgo! - The Go Programming Language
March 17, 2011 - Cgo lets Go packages call C code.
GitHub
github.com › golang › go › blob › master › src › runtime › cgo.go
go/src/runtime/cgo.go at master · golang/go
//go:linkname _cgo_callers _cgo_callers · //go:linkname _cgo_set_traceback_functions _cgo_set_traceback_functions · //go:linkname _cgo_call_traceback_function _cgo_call_traceback_function · //go:linkname _cgo_call_symbolizer_function _cgo_call_symbolizer_function ·
Author golang
Karthikkaranth
karthikkaranth.me › blog › calling-c-code-from-go
Calling C code from go | Karthik Karanth
C.CString is a cgo function that takes a go string and returns a pointer to a C char, ie: *C.char. This allows us to pass strings to C code. Note that this function uses malloc to create the space for the string, so we need to call the C function free once we are done with the string to prevent memory leaks.
Golang
golang.bg › pkg › runtime › cgo
cgo - Packages - Go Documentation Server
Package cgo contains runtime support for code generated by the cgo tool.
Akrennmair
akrennmair.github.io › golang-cgo-slides
Go & cgo: integrating existing C code with Go
Golang User Group Berlin · Twitter: @der_ak · Go is meant to be a practical language · Integration with existing software, infrastructure and protocols necessary · Ability to use existing C code is crucial for success (case in point: C++) Go's solution: cgo ·
7-Zip Documentation
documentation.help › Golang › cgo.html
cgo - go-wiki - Tips for interfacing with C code and libraries using cgo. - Go Language Community Wiki - Google Project Hosting - Golang Documentation
documentation.HELP! Golang Documentation · previous page next page · Project Home Wiki · Terms - Privacy - Project Hosting Help · Powered by Google Project Hosting · previous page start next page ·
Victor on Software
victoronsoftware.com › posts › using-c-and-go-with-cgo-is-tricky
Using C and Go with CGO is tricky - Victor on Software
January 18, 2024 - CGO is a way to call C code from Go. It helps call existing C libraries or for performance reasons.