Search code examples
c++ide

Calling g++ in c++ source code


So I already searched everything I could have. I'm writing my own IDE using C++ and I'm trying to find a way to call g++ or any other compiler. The only way I have thinked of so far is as such:

int main(){
   system("g++ --flags");
   return 0;
}

Do you guys know or can think of any other way to do this in c++?

Best regards, Zé Pedro


Solution

  • The most "raw" way is using your OS's API: the exec() family on POSIX, CreateProcess[Ex] on Windows.

    Quite often, you can also use this through a platform-independent abstraction. It's quite likely the toolkit you're using for GUI (whatever it is) already has process-launching functionality as part of its API. For example, Qt has QProcess, wxWidgets has wxExecute().