我使用这种方法在VS中编译C++文件。但是,即使我提供了正确的文件,它也会返回false。谁能帮我...
这是称为CL的类(class)
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;
}
}
这是我的按钮点击事件
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);
}
最佳答案
在Visual Studio安装文件夹中,应具有以下路径:
VC\bin\x86_amd64\1033\1033
此路径中应该有一个
clui.dll
。将其复制到父文件夹(VC\bin\x86_amd64\1033
)。这应该可以解决您的问题。我从http://connect.microsoft.com/VisualStudio/feedback/details/108528/command-line-issue-when-building-for-64bit-in-32bit-with-cl-exe获取解决方案: