
I've added /usr/local/lib to /etc/ld.so.conf and now it works. What I don't understand is why the linker didn't complain (the problem was when executing),
That's actually the way dynamic linking works under UNIX: You tell the linker which libraries to link with, but aren't tied to this library location when you deploy the program (e.g. on a different computer). Hence you use the -L directive to tell gcc/ld where to look for libraries (shared or static), and have to edit ld.so.conf to tell the dynamic linker (the program which looks through all referenced dynamic libraries for symbols when you start your executable) where to look for libraries when running executables. Note, that you don't have to edit ld.so.conf: you could instead set the variable LD_LIBRARY_PATH to the library location (works like the PATH environment variable, so you can provide multiple paths separated by colons). This way you can accomplish your task without super user privileges. Note, that the variable is called DYLD_LIBRARY_PATH on Mac OSX systems.