Guilds are not something you build — they approach you. Keep a reasonably strong economy and a stable army, avoid collapsing into debt, and after roughly 15 turns a guild will usually offer its services.
Each guild grants a bonus, such as cheaper recruitment or improved research, so it is worth protecting the settlement that hosts one.