Yeah, you always have to make sure you include the right libraries in the right order when you link.
The "-Ldirectory" flag says add "directory" to the library path, so it can find the library. The "-llibrary" says link with the file liblibrary.a or liblibrary.dylib (on Macs). On most Unixes, dynamic libraries are .so, not .dylib.
About link order, if you have two libraries, libfoo.a and libbar.a, and libfoo depends on libbar, libfoo should come first on the link line, then libbar. I.e.
cc -o program program.c -lfoo -lbar
dave