How to Integrate C++ compiler in Visual Studio 2008

This is a discussion on How to Integrate C++ compiler in Visual Studio 2008 within the C# Programming forums, part of the General Programming Boards category; Hi, Can someone help me with this issue? I currently working on my project for final year of my honors ...

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    4

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

    Hi,

    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
    Code:
    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;
                    }
                }
                else
                {
                    //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
                }
    
    Attached Images Attached Images  

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    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.
    hth
    -nv

    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
    Posts
    4

    Exclamation

    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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,470
    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
    Code:
    System.Object
      System.MarshalByRefObject
        System.ComponentModel.Component
          System.CodeDom.Compiler.CodeDomProvider
            Microsoft.CSharp.CSharpCodeProvider
            Microsoft.JScript.JScriptCodeProvider
            Microsoft.VisualBasic.VBCodeProvider
    so as I see it - for c++ - run the command line compiler and parse its output like the IDE does it
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    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
    Posts
    4

    Smile

    To Bubba:


    Quote Originally Posted by Bubba View Post
    You could actually do this from a batch file as well.
    Code:
     
    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""",
                };
                Process.Start(psi);
    You mention about this kind of solution to button click?

  7. #7
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    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
    Posts
    4
    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, 02:17 PM
  3. multiple errors generated by socket headers
    By nocturna_gr in forum Windows Programming
    Replies: 5
    Last Post: 12-16-2007, 05:33 PM
  4. Erros in Utility Header File
    By silk.odyssey in forum C++ Programming
    Replies: 4
    Last Post: 12-22-2003, 05:17 AM
  5. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 04:44 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21