Sebastian Dusza
Sebastian Dusza

Reputation: 2528

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 classes), preferably LGPL/BSD licence :)

As far as I know it can be done in Java and c#. What about c++ ?

Upvotes: 0

Views: 3225

Answers (6)

user548569
user548569

Reputation: 158

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/

Upvotes: 1

Zaphod
Zaphod

Reputation: 21

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.

Upvotes: 2

Alexandre C.
Alexandre C.

Reputation: 56976

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.

Upvotes: 2

Harald Scheirich
Harald Scheirich

Reputation: 9764

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

Upvotes: 4

Klaim
Klaim

Reputation: 69772

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.

Upvotes: 4

tdammers
tdammers

Reputation: 20706

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.

Upvotes: 1

Related Questions