簡體   English   中英

如何使用mingw32-gcc編譯器以編程方式從ac#代碼編譯ac代碼

[英]How to programmatically compile a c code from a c# code using mingw32-gcc compiler

我想以編程方式從c#編譯C代碼。 我正在嘗試,但我還沒有找到任何解決方案。 這是我的代碼。

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

我在Windows 7中使用VS2010,我已經安裝了mingw32-gcc,mingw32-gcc的環境變量是C:\\ Program Files \\ CodeBlocks \\ MinGW \\ bin任何幫助將不勝感激。 提前致謝。

嘗試

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

不需要調用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 );

問候

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM