【发布时间】:2012-06-03 02:04:44
【问题描述】:
如何在 LLVM 中声明 stdin、stout 和 stderr(最好是 C 版本)?我正在尝试在我正在创建的玩具语言中使用一些 stdio 函数。一个这样的功能是fgets:
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 提供的功能。
标签: llvm