Search code examples
c++pythoncompilation

Using scripting language in C++


I want to make a "dynamic" C++ program. My idea is to compile it and after compilation (maybe with scripting language like python) to change some how the code of the program. I know you will tell me that after the compilation I can not change the code but is there a way of doing that?


Solution

  • The only way to do that in C++ is to unload the DLL with the code to be modified, modify the sources, invoke the compiler to regenerate the DLL, and reload the DLL. It's very, very heavy weight, and it only works if the compiler is present on the machines where the code is to be run. (Usually the case under Unix, rarely the case with Windows.)

    Interpreted languages like Python are considerably more dynamic; Python has a built-in function to execute a string as Python code, for example. If you need dynamically modifiable code, I'd suggest embedding Python in your application, and using it for the dynamic parts.