Invoke the MS C++ Compiler at the run time

Hello,

I really don't know if this related to this forum, But I thought a lot and I found it suitable. All I just want is invoke the MS compiler at the run time and give it the suitable parameters for compilation. and get the errors of it. This is really a useful for our project. Will we invoke it using the shell api!!

Thanks,

Mustafa ELBanna



Answer this question

Invoke the MS C++ Compiler at the run time

  • Steven Somer

    I tried this:

    system("CALL \"C:\\Program Files\\Microsoft Visual Studio 8\\VC\\bin\\vcvars32.bat\"");

    system("CD \"C:\\Program Files\\Microsoft Visual Studio 8\\VC\\\"");

    system("cl.exe \"c:\\main.c\"");

    and I get error:

    "This application has failed to start because mspdb80.dll was not found. Re-installing the application may fix this problem."

    Thanks,

    Mustafa ELBanna


  • theikell

    MustafaELBanna wrote:

    system("CALL \"C:\\Program Files\\Microsoft Visual Studio 8\\VC\\bin\\vcvars32.bat\"");

    system("CD \"C:\\Program Files\\Microsoft Visual Studio 8\\VC\\\"");

    system("cl.exe \"c:\\main.c\"");

    The first line (the vital one, the one which set up your necessary environment variables) was ineffectual. The first line opened up a new command interpreter (CMD), ran vcvars32.bat from within that interpreter, then when it completed, shut that command interpreter instance down, and it took the environment variables with it.

    Without those environment variables, it's no wonder you got errors afterward. In order for batches to work, you MUST perform one system statement only, no more no less.

    Exercise: How would you code system() such that it would execute a number of statements in just one call

    Hint: what does the first line in your posted code do



  • dragon_ballz96

    The simple answer is to use a batch file by your own. Or you determine the needed environment variables by your won, and pass it as a separate data block to _spawnle instead of system.

  • Peter Stromquist

    I recall someone asking a similar question last month. You can check out the discussion here:

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=223378&SiteID=1



  • koko_han

    Yes! The compiler is just a normal console program, so you can redirect the output accordingly. The pathes and environment variables should be set correct.

  • Invoke the MS C++ Compiler at the run time