如何使用mingw32-gcc编译器以编程方式从ac#代码编译ac代码

我想以编程方式从c#编译C代码。 我正在尝试,但我还没有找到任何解决方案。 这是我的代码。

try { var info = new ProcessStartInfo { FileName = "cmd.exe", Arguments = "mingw32-gcc -oa Test.c" }; var process = new Process { StartInfo = info }; bool start = process.Start(); process.WaitForExit(); if (start) { Console.WriteLine("done"); } } catch (Exception) { Console.WriteLine("Not done"); } 

我在Windows 7中使用VS2010,我已经安装了mingw32-gcc,mingw32-gcc的环境变量是C:\ Program Files \ CodeBlocks \ MinGW \ bin任何帮助将不胜感激。 提前致谢。

不需要调用cmd.exe程序。 您可以使用参数直接调用mingw32-gcc.exe程序。

编辑:

 string szMgwGCCPath = "C:\\mingw32\\bin\\mingw32-gcc.exe"; // Example of location string szArguments = " -c main.c -o main.exe"; // Example of arguments ProcessStartInfo gccStartInfo = new ProcessStartInfo(szMgwGCCPath , szArguments ); gccStartInfo.WindowStyle = ProcessWindowStyle.Hidden; Process.Start(gccStartInfo ); 

问候

尝试

 Process process = Process.Start( @"C:\Program Files\CodeBlocks\MinGW\bin\mingw32-gcc.exe", "-oa Test.c");