如何在LLVM中聲明stdin
,stout
和stderr
(最好是C版本)?我正在嘗試使用我創建的玩具語言中的某些stdio函數。一個這樣的功能是fgets
:LLVM stdin/stdout/stderr
char * fgets (char * str, int num, FILE * stream);
爲了使用,我需要stdin
。所以我寫了一些LLVM API代碼來生成我發現的FILE的定義,並且聲明瞭一個外部全局的stdin
。生成的代碼如下:
%file = type { i32, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, %marker*, %file*, i32, i32, i64, i16, i8, [1 x i8], i8*, i64, i8*, i8*, i8*, i8*, i64, i32, [20 x i8] }
%marker = type { %marker*, %file*, i32 }
@stdin = external global %file*
然而,當我跑了生成的模塊,它給了我這個錯誤:
Undefined symbols for architecture x86_64:
"_stdin", referenced from:
_main in cc9A5m3z.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
很顯然,我寫的沒有工作。所以我的問題是我需要在LLVM API中編寫什麼來聲明stdin
,stout
和stderr
,像fgets
這樣的函數,就像玩具語言編譯器一樣?
你可以在C中編寫幫助函數,它將返回stdin/stdout/stderr並將它們與你的程序連接起來。 –
我會盡力,儘管如果可以的話,我寧願使用LLVM API給我們做的事情。 – tophat