假設我有C#程序,並且我將在開始時將foo.c文件作爲輸入。如何在運行時編譯C代碼並使用它功能
是否可以在我的C#程序中使用foo.c文件中的函數?如果可能,我該怎麼做?
編輯:這就是我想要做的
在C#中一部分的例子:
int main()
{
string filePath = "SampleCode.c";
string SourceCode = File.ReadAllText("SampleCode.c");
//I want to some how compile this source code here
***
function1();
function2();
}
在SampleCode.c
:
#include <stdio.h>
function1()
{
...
}
function2()
{
...
}
你能告訴我如何編譯這個文件並將其動態鏈接到一個DLL? –
這取決於你想要使用的編譯器。選擇一個編譯器並檢查它的文檔。 –