I use TCC for this type of thing. TCC is a small, fast C99 compiler that is also a library (so it can be embedded in an application). It can compile code into memory which can then be called (in fact, the same code can be re-compiled multiple times, each time resulting in new code).
On the down side, it only supports x86, X86-64 and Arm architectures.
On the down side, it only supports x86, X86-64 and Arm architectures.