0

Is there a GCC C API (or some other C API) that I can use within a C program to compile other C programs? Something more programmatic than exec("gcc") and having to parse text intended for man (not machines) (eg. for debugging).

More specifically, the idea is to have a C program modify its C source code at run-time and then replace its own running instance (or parts of it; say it's made of multiple dynamic libraries that can be reloaded) with the newly compiled version of itself.

  • What you want may be [just-in-time compilation](https://en.wikipedia.org/wiki/Just-in-time_compilation) or JIT for short. GCC has [a library called `libgccjit`](https://gcc.gnu.org/wiki/JIT) for this. – kotatsuyaki Feb 04 '23 at 12:35
  • OpenCL kernels are typically compiled at run-time. I think they can be generated dynamically in the host program. – Simon Goater Feb 04 '23 at 12:59

0 Answers0