Thread: How to Integrate C++ compiler in Visual Studio 2008

  1. #1
    Registered User
    Join Date
    Jun 2010

    Question How to Integrate C++ compiler in Visual Studio 2008


    Can someone help me with this issue?

    I currently working on my project for final year of my honors degree. And we are developing a application to evaluate programming assignments of student ( for 1st year student level)

    And we are working with Visual Studio 2008.

    I just want to know how to integrate C++ compiler using C# code to compile C++ code.

    In our case we are loading a student C++ code into text area, then with a click on button we want to compile the code. And if there any compilation errors it will be displayed on text area nearby. (Interface is attached herewith.)

    And finally it able to execute the code if there aren't any compilation errors. And results will be displayed in console.

    We were able to do this with a C#(C# code will be loaded to text area intead of C++ code) code using inbuilt compiler. But still not able to do for C# code.

    Can anyone suggest a method to do this? It is possible to integrate external compiler to VS C# code? If possible how to achieve it?

    Very grateful if anyone will contributing to solve this matter?

    This is code for Build button which we proceed with C# code compiling
    CodeDomProvider codeProvider = CodeDomProvider.CreateProvider("csharp");
                string Output = "Out.exe";
                Button ButtonObject = (Button)sender;
                rtbresult.Text = "";
                System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
                //Make sure we generate an EXE, not a DLL
                parameters.GenerateExecutable = true;
                parameters.OutputAssembly = Output;
                CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, rtbcode.Text);
                if (results.Errors.Count > 0)
                    rtbresult.ForeColor = Color.Red;
                    foreach (CompilerError CompErr in results.Errors)
                        rtbresult.Text = rtbresult.Text +
                                    "Line number " + CompErr.Line +
                                    ", Error Number: " + CompErr.ErrorNumber +
                                    ", '" + CompErr.ErrorText + ";" +
                                    Environment.NewLine + Environment.NewLine;
                    //Successful Compile
                    rtbresult.ForeColor = Color.Blue;
                    rtbresult.Text = "Success!";
                    //If we clicked run then launch our EXE
                    if (ButtonObject.Text == "Run") Process.Start(Output); // Run button

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Hannover, Germany
    Do you get any errors when you switch your CodeDom to "cpp" or "c++" ?

    You can find an example of listing all supported languages here.

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    Jun 2010


    Seems not working with both ("cpp") or ("c++") . I replaced the code with those but no result. I think there will be very small modification to do. But still cannot grasp any idea to solve the issue.

    Anyway thanks for concern.

    Appreciate if u keep trying to figure the issue out.

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    If you know at design time which code provider is to be used, you should create an instance of that code provider rather than use the CreateProvider method.
    Inheritance Hierarchy
    so as I see it - for c++ - run the command line compiler and parse its output like the IDE does it
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    so as I see it - for c++ - run the command line compiler and parse its output like the IDE does it
    You could actually do this from a batch file as well. You can run the compiler from the command line and it will spit all the errors and warnings to std::out. MSDN has a lot of documentation about how to execute the compiler from the command line and what each argument does. I use this a lot to create batch files to build solutions and to build components without having to load said component solutions up in the IDE.

  6. #6
    Registered User
    Join Date
    Jun 2010


    To Bubba:

    Quote Originally Posted by Bubba View Post
    You could actually do this from a batch file as well.
    private void button1_Click(object sender, EventArgs e)
                ProcessStartInfo psi = new ProcessStartInfo
                    FileName = "cmd",
                    Arguments = @"/k ""C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\vcvars32.bat""",
    You mention about this kind of solution to button click?

  7. #7
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Yes, that kind of a solution would work. Well, you can use a much simpler scripting language and do this in 1-2 lines, but whatever works for you.

  8. #8
    Registered User
    Join Date
    Jun 2010
    What will you mean by "much simple scripting language"?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what am I missing? (Program won't compile)
    By steals10304 in forum C Programming
    Replies: 3
    Last Post: 08-25-2009, 03:01 PM
  2. sorting the matrix question..
    By transgalactic2 in forum C Programming
    Replies: 47
    Last Post: 12-22-2008, 03:17 PM
  3. multiple errors generated by socket headers
    By nocturna_gr in forum Windows Programming
    Replies: 5
    Last Post: 12-16-2007, 06:33 PM
  4. Erros in Utility Header File
    By silk.odyssey in forum C++ Programming
    Replies: 4
    Last Post: 12-22-2003, 06:17 AM
  5. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM

Tags for this Thread