cgo directives: CFLAGS, LDFLAGS, and pkg-config
WHAT IT TESTS: cgo build configuration. OUTLINE: #cgo CFLAGS feeds the C compiler include paths/defines, LDFLAGS feeds the linker libraries/paths, pkg-config auto-discovers both; needed to compile against a system C library.
WHAT IT TESTS: knowledge of how cgo configures the underlying C toolchain. ANSWER OUTLINE: in the preamble comment above import "C", #cgo lines pass options to the toolchain. CFLAGS goes to the C compiler, supplying -I include paths and -D defines so the C snippet compiles. LDFLAGS goes to the linker, supplying -L search paths and -l libraries so symbols resolve. pkg-config queries .pc files to emit both automatically. You can scope directives per-OS. RED FLAG: swapping the compile-time and link-time roles.
Read the original → interview
- #go
- #cgo
- #build
- #linking
- #pkg-config
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.