Running example C code is a painful exercise unless it comes with a makefile.
I often find myself with a C file containing code that supposedly does something very cool, but for which a first basic attempt at compilation (
gcc main.c) fails with—
main.c:(.text+0x1f): undefined reference to `XListInputDevices' clang-3.7: error: linker command failed with exit code 1 (use -v to see invocation)
I know this means I'm missing the right linker flags, like
But which ones?
The way I currently deal with this is to find the library header that a function was included from, use Github's search to find some other program that imports that same header, open its makefile, find the linker flags, copy them onto my compilation command, and keep deleting flags until I find a minimal set that still compiles.
This is inefficient, boring, and makes me feel like there must be a better way.