Is there a C / C ++ compiler / linker that can be embedded directly into a C / C ++ program?

The idea is to generate C / C ++ code at runtime, compile it for a shared object, and load that shared object into the current process.

I know that this can be done using an existing compiler installation on the host platform (GCC or MSVC), but in a practical scenario the client does not have such an installation. Therefore, the idea is to statically link to such a compiler and linker.

For example, in Java, you can compile .java classes directly from java code. It can be used to automatically create Buisness objects from a database schema.

+4
source share
5 answers

You can do this using the c-language ( clang ) interface before llvm . A static analyzer built on top of clang can give you some ideas on how to proceed.

+2
source

There is tinyC: http://bellard.org/tcc/ . I don't know anything like this for C ++.

+1
source

Google 'c interpreter embed' and you get the first hits

Ymmv

+1
source

As far as I know, such a thing cannot be done for c or C ++. You need to start a new process (in which you run the compiler) and requires that the compiler be installed.

0
source

You might want to take a look at llvm-based tracking language at an early stage, but it seems pretty close to what you are trying to achieve.

0
source

All Articles