In my last post I mentioned having trouble with the order of command options in gcc. I finally found a mention of this in the documentation.
The relevant passage: It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, `foo.o -lz bar.o’ searches library `z’ after file foo.o but before bar.o. If bar.o refers to functions in `z’, those functions may not be loaded.
So, the libraries have to be stated after the source files that will need to refer to them, which is the opposite of what I thought it would be! Thankfully the error message was somewhat sensible, saying “undefined reference to…” which I know from past experience is a linker error as opposed to a header not being found (right?).