Hmm... this was a FAQ but I can't find it anymore.
To compile yoiur project from the command line, you have to pass the same arguments as Lazarus does. When you compile in Lazarus, you can see the command on the console.
To make it easier, you can add the -Fu -Fi etc. directives to your fpc.cfg.
something like:
-Fu/usr/src/lazarus/lcl/units/i386/$target
-Fu/usr/src/lazarus/lcl/units/i386/$target/gtk
-Fu/usr/src/lazarus/components/units/i386/$target
-Fu/usr/src/lazarus/ideintf/units/i386/$target
-Fu/usr/src/lazarus/ideintf/units