2

In C# I can use CSharpCodeProvider to take in a file and compile it on the fly.

I want the same thing for C++. Essentially I'm trying to compile a .dll from a file specified at runtime and dynamically link it to the executing program.

I'm sure there's some crazy library out there that does this, but what I was hoping is that there is a library in either the Standard Library or Boost which does this. Does anyone know of one?

Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
  • 1
    Have you seen this: http://stackoverflow.com/a/19730718/390913 – perreal Apr 10 '15 at 11:57
  • 1
    Technically, every dll is compiled "at runtime" – sehe Apr 10 '15 at 12:03
  • @perreal That's actually really similar to this question, but it looks like he's asking for a way to compile C++ code from C#. I'm looking for a C++ runtime compiler for C++. Which from [gha.st](http://stackoverflow.com/users/65678/gha-st)'s answer may not be available. – Jonathan Mee Apr 10 '15 at 12:04
  • @sehe I see your point, perhaps my question is a bit redundant, but hopefully it is correctly communicating what I am asking. – Jonathan Mee Apr 10 '15 at 12:06

1 Answers1

2

No, there is nothing like this in the standard library or boost.

There is however clang which is a full C++ compiler built on LLVM which is organized as a library that you can (with "some" work) use in your program.

@Perreal also pointed out correctly that if you are using C++/CLI (which is usually not included when talking about C++ in general), you can access a .NET component that will allow you to compile C++/CLI code - but not native C++ code.

Community
  • 1
  • 1
danielschemmel
  • 10,885
  • 1
  • 36
  • 58
  • Seems like this is the correct answer. Is there possibly an example of clang being used as a library for runtime compilation? – Jonathan Mee Apr 10 '15 at 13:30
  • 1
    @JonathanMee [There is a very similar question with several interesting answers](http://stackoverflow.com/questions/3224485/any-tutorial-for-embedding-clang-as-script-interpreter-into-c-code) – danielschemmel Apr 10 '15 at 15:36