Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ compilation at runtime

So I watched this video months back where Epic showcased their new Unreal Engine 4 developer features. Sorry I could not find the video but I'll try my best to explain.

The one feature that got my attention was the C++ "on the fly" modification and compilation. The guy showed how he was playing the game in editor and modified some variables in the code, saved it and the changes were immediately mirrored in game.

So I've been wondering... How does one achieve this? Currently I can think of two possible ways: either a hoax and it was only "c style"-scripting language not C++ itself OR it's shared library (read: DLL) magic.

Here's something I whipped up to try myself(simplified):

for(;;)
{
    Move DLL from build directory to execution directory
    Link to DLL using LoadLibrary() / dlopen() and fetch a pointer to function "foo()" from it
    for(;;)
    {
        Call the function "foo()" found in the dll
        Check the source of the dll for changes
        If it has changed, attempt to compile
        On succesfull compile, break
    }
    Unload DLL with FreeLibrary() / dlclose()
}

Now that seems to work but I can't help but wonder what other methods are there? And how would this kind of approach compare versus using a scripting language?

edit: https://www.youtube.com/watch?v=MOvfn1p92_8&t=10m0s

like image 904
TheDespite Avatar asked Jan 31 '26 03:01

TheDespite


1 Answers

Yes, "hot code modification" it's definitely a capability that many IDEs/debuggers can have to one extent or another. Here's a good article:

  • http://www.technochakra.com/debugging-modifying-code-at-runtime/

Here's the man page for MSVS "Edit and Continue":

  • http://msdn.microsoft.com/en-us/library/esaeyddf%28v=vs.80%29.aspx
like image 176
paulsm4 Avatar answered Feb 02 '26 21:02

paulsm4