I'm thinking of creating a Game Engine with a C++ Compiler using OpenGL but I don't know how to create a compiler in an application. Do I have to write the compiler? or could I use (for example) the Visual C++ Compiler?
The only reason that I can see for including a compiler in an application is that you wish users to be able to write their own code in C++ which is compiled, linked, and executed at runtime. This isn't a brilliant idea, and in fact there is a common game engine technique called scripting that allows users to do write their own code and have it executed.
A short extract from Jason Gregory's Game Engine Architecture (third edition) from page 794 can be found below:
A scripting language can be defined as a programming language whose primary purpose is to permit users to control and customise the behaviour of a software application.
In the context of game engines, a scripting language is a high level, relatively easy-to-use programming language that provides its users with convenient access to most of the commonly used features of the engine. As such, a scripting language can be used by programmers and non-programmers alike to develop a new game or to customise - or "mod" - an existing game.
A short list of benefits of scripting:
- You can only expose the parts of the engine to the scripting system that you want to.
- The scripts are loaded at runtime and can be edited off-line without the engine needing to be recompiled.
- They help support rapid iteration times and are sometimes quite lightweight.
I would suggest you look into adding scripting functionality as this would be a better solution to your problem. There are many scripting related questions on gamedev.stackexchange to get you started!