compile and run c++ code runtime

匿名 (未验证) 提交于 2019-12-03 02:33:02

问题:

Does anyone know how to compile your c++ code wich you write while your program is already running?

And later i would like to run that code.

I want to do this because I am trying to make a game that woul teach you programing and so the user would have to write the code while the game is running and test it.

Thanks for any help

回答1:

You'd have an easier time if you chose a language that was designed with embedding in mind - like LUA or python. For C++, you'd have to go for something extremely clumsy and fragile like invoking an external compiler (which is also a logistics nightmare when shipping your game), or something as complex as integrating a compiler in your game (probably doable with llvm components, but...)

Also, for "teaching programming", C++ probably isn't the best language :)



回答2:

You have to call the compiler to compile and link the user-entered code. This has to be made either into an executable that is then run from another process you create, or as a library that you dynamically load and call.

How this is done is different on POSIX platforms (like Linux and OSX) and Windows.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!