本文介绍了如何以编程方式编译使用的mingw32-gcc编译一个C#代码中的C代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望以编程方式编译从C#中的C代码。我想,但我没有找到任何解决办法呢。这里是我的代码。

I want to compile a C code from c# programmatically. I am trying but i have not found any solution yet. Here is my code.

try {
    var info = new ProcessStartInfo {
        FileName = "cmd.exe",
        Arguments = "mingw32-gcc -o a 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");
}



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

I am using VS2010 in windows 7 and I have installed mingw32-gcc and my environment variable for mingw32-gcc is C:\Program Files\CodeBlocks\MinGW\binAny Help will be appreciated. Thanks in advance.

推荐答案

调用cmd.exe程序是没有必要的。您可以直接调用与参数的mingw32-gcc.exe程序

Calling the cmd.exe program is not necessary. You can directly call the mingw32-gcc.exe program with arguments.

编辑:

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 );



问候

Regards

这篇关于如何以编程方式编译使用的mingw32-gcc编译一个C#代码中的C代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 06:16