views:

129

answers:

5

Hi, is there a multiplatform c++ compiller 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++ ?

Thanks

+1  A: 

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.

tdammers
+2  A: 

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.

Klaim
Looks promising. Thanks.
Seba
+3  A: 

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

Harald Scheirich
+3  A: 

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.

Alexandre C.
I was considering C++ bacause of performance. I wonder how much slower v8 runns js code compared to similar c++ code.
Seba
there is just in time compilation with V8, soou should definitely benchmark. I believe however that the ease of use of V8 will offset the problems you'll encounter if you try to compile C++ code on the fly.
Alexandre C.
+1  A: 

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.

Zaphod
Good thinking :)
Seba
I did it once too (a parser were taking an equation, and C code was generated on the fly). The problem is that you need a full development environment, which you have to deploy with your application. On linux it is generally not a problem, but on other platforms it is. Moreover, there are security risks with this approach. Imho, scripting is superior, even in situations where you need speed.
Alexandre C.