views:

493

answers:

4

Hello,

There is very good compiler tcc and its library libtcc, that allows direct compilation of code inside code. i.e. Allows creation of self-generated code.

I'm looking for similar library for C++, if any exists. Or, I need and extremely fast reasonably good C++ compiler, so I may run it to generate shared object and dlopen it. I don't care about the performance of target code.

Is there anything like that?

Platform UNIX, ELF. Linux only is ok as well.

A: 

You may try with Intel's compiler. Gloogling it, it seems known to be faster that g++ at compile time and in optimisations it provide in the resulted binary.

Also you may try re-compiling "g++" binary from source tarball, and requesting optimisation for the host machine you are targeting. Maybe it could make it faster then to compile any code (?)

Whatever the solution you choose, I advise you to keep the same compiler for your application and your "plugin". Otherwise I suspect some ABI problems which could arise when using 2 different compilers in the same application project. (I only suspect ... As I never had such issues, but browsing SO questions, I've already seen such issues for others...)

yves Baumes
+1  A: 

You might want to check out LLVM. It is an industrial strength compiler (to be included in gcc) developed by Apple and with broad support, and has enjoyed a lot of success in various JIT environments like you describe.

Greg
+1  A: 

Use system() to call c++ or libtool to produce your .so.

g++ -O1 is pretty fast especially if you use a precompiled header for building.

Zan Lynx
++ RIght. It's the includes and the optimizations that take a lot of time.
Mike Dunlavey
A: 

to creg. llvm is not developed by apple.

lbz