Generating C++ code at runtime, compiling and running it
is there a multiplatform c++ compiler that could be linked into any software ?
Lets say I want to generate c++ code at runtime, compile it and run it. I'm looking for a compact solution (bunch of classe开发者_开发问答s), preferably LGPL/BSD licence :)
As far as I know it can be done in Java and c#. What about c++ ?
Well maybe one of the modules of CLang will be of help? It's not dry yet on the C++ side but certainly will be soon.
I don't know of any open source ones for C++, but if you want small and compact scripting and are not hung up on C++ LUA might be an option for you
I'd drop C++ altogether and use Google V8. If you wanted to use C++ because the people using your app only know this, they should have no difficulties going to javascript.
And it's damn fast. And Javascript is a cool language too.
I've done this years ago in Linux by generating C++-code into a file, compile it by shell execute (with gcc) and then linking in the generated library dynamically. The dynamic linking differs of course between platforms.
This kind of thing is much much harder in C++, because the language doesn't use a virtual machine (or "runtime") that abstracts machine specifics away.
You could look into gcc, it's under the GPL IIRC, and ports exist for all major platforms.
When we looked into scripting we chose AngelScript because of the similarity with C++. V8 is great but it's certainly limited to some platforms, AngelScript is a lot easier to compile with and probably to learn (if you came from C++) and it has a zlib license. http://www.angelcode.com/angelscript/
精彩评论