gcc - Embed C++ compiler in application -
aren't shaders cool? can toss in plain string , long valid source, compile, link , execute. wondering if there way embed gcc inside user application "self sufficient" e.g. has internal capability compile native binaries compatible itself.
so far i've been invoking stand alone gcc process, started inside application, wondering if there api or allow use "directly" rather standalone compiler. also, in case possible, permitted?
edit: although original question cgg, i'd settle information how embed llvm/clang too.
and special edit people cannot put 2 + 2 together: question asks how embed gcc or clang inside of executable in way allows internal api used code rather invoking compilation command prompt.
i'd add +1 suggestion use clang/llvm instead of gcc. few reasons why:
- it more modular , flexible
- compilation time can substantially lower gcc
- it supports platforms listed in comments
- it has api can used internally
string source = "app.c"; string target= "app"; llvm::sys::path clangpath = llvm::sys::program::findprogrambyname("clang"); // arguments vector<const char *> args; args.push_back(clangpath.c_str()); args.push_back(source.c_str()); args.push_back("-l"); args.push_back("curl"); clang::textdiagnosticprinter *diagclient = new clang::textdiagnosticprinter(llvm::errs(), clang::diagnosticoptions()); clang::intrusiverefcntptr<clang::diagnosticids> diagid(new clang::diagnosticids()); clang::diagnosticsengine diags(diagid, diagclient); clang::driver::driver thedriver(args[0], llvm::sys::getdefaulttargettriple(), target, true, diags); clang::owningptr<clang::driver::compilation> c(thedriver.buildcompilation(args)); int res = 0; const clang::driver::command *failingcommand = 0; if (c) res = thedriver.executecompilation(*c, failingcommand); if (res < 0) thedriver.generatecompilationdiagnostics(*c, failingcommand);
Comments
Post a Comment