Set g++ flags and link examples against library before installing

This patch sets proper compiler flags if g++ is used to build the library, and allows example executables to link against the library without installing it first.