Sorry I'm this late to the party.
It's a quirk of gcc. Your command doesn't work, but
g++ main.cpp -lQuantLib
does instead (see, for instance, Why does the order in which libraries are linked sometimes cause errors in GCC? for a thourough explanation; in short, gcc scans arguments from left to right, and won't load anything from QuantLib if it's the first argument because no other code requested any of its functionality yet).