views:

154

answers:

2

Hi All.. I use this method to compile C++ file in VS. But even i provide the correct file it returns false. Can any one help me... This is class called CL

class CL
{
    private const string clexe = @"cl.exe";
    private const string exe = "Test.exe", file = "test.cpp";
    private string args;

    public CL(String[] args)
    {
        this.args = String.Join(" ", args);
        this.args += (args.Length > 0 ? " " : "") + "/Fe" + exe + " " + file;
    }

    public Boolean Compile(String content, ref string errors)
    {
        if (File.Exists(exe))
            File.Delete(exe);
        if (File.Exists(file))
            File.Delete(file);

        File.WriteAllText(file, content);

        Process proc = new Process();
        proc.StartInfo.UseShellExecute = false;
        proc.StartInfo.RedirectStandardOutput = true;
        proc.StartInfo.RedirectStandardError = true;
        proc.StartInfo.FileName = clexe;
        proc.StartInfo.Arguments = this.args;
        proc.StartInfo.CreateNoWindow = true;

        proc.Start();
        //errors += proc.StandardError.ReadToEnd();
        errors += proc.StandardOutput.ReadToEnd();

        proc.WaitForExit();

        bool success = File.Exists(exe);

        return success;
    }
}

This is my button click event

    private void button1_Click(object sender, EventArgs e)
    {
        string content = "#include <stdio.h>\nmain(){\nprintf(\"Hello world\");\n}\n";
        string errors = "";

        CL k = new CL(new string[] { });
        if (k.Compile(content, ref errors))
            Console.WriteLine("Success!");
        else
            MessageBox.Show("Errors are : ", errors);
    } 
A: 

In your Visual Studio installation folder there should be the following path:

VC\bin\x86_amd64\1033\1033

There should be a clui.dll in this path. Copy it to the parent folder (VC\bin\x86_amd64\1033). This should solve your problem.

I took the solution from http://connect.microsoft.com/VisualStudio/feedback/details/108528/command-line-issue-when-building-for-64bit-in-32bit-with-cl-exe:

Aurril
you mean to add the clui.dll to debug folder. I done it. But still same error. Is there anything i need to set
Kasun
I expect it'll be looking for clui.dll either in a locale-specific directory relative to cl.exe or to something in your path. I'd open a Visual Studio command prompt (or run vsvars32.bat in a regular command prompt) then try running your built .exe from there, preferably away from any cl.exe or clui.exe that you've copied around, to see if it's just an environment problem.
Rup
So, Is there any solution for it..
Kasun
A: 

Maybe it is not relevant, but I think you miss a space in your command line...

this.args += (args.Length > 0 ? " " : "") + "/Fe" + exe + " " + file;

right after the "/Fe"

Shimrod
I gave it. But still not working :(
Kasun