If you are using configure/make you can use AutoToolsBuildEnvironment helper.
This helper sets LIBS
, LDFLAGS
, CFLAGS
, CXXFLAGS
and CPPFLAGS
environment variables based on your requirements.
Check :ref:`Building with Autotools <autotools_reference>` for more info.