我一直在尝试学习ANTLR,并使用这教程(也在这问题中引用)让它使用C输出代码。我成功地让ANTLR作为C源代码生成了lexer和解析器,但我无法让它们在Mac雪豹上使用gcc编译(i 686-apple-darwin10-GCC-4.2.1)。下面是当我试图编译“SimpleCalcLexi.c”时的结果。
dyn-72-33-132-199:Desktop bf$ gcc -o lexer SimpleCalcLexer.c
Undefined symbols:
"_main", referenced from:
start in crt1.10.6.o
"_antlr3LexerNewStream", referenced from:
_SimpleCalcLexerNewSSD in ccjXa6NU.o
ld: symbol(s) not found
collect2: ld returned 1 exit statusC文件不引用"main“任何地方(也没有定义),但是解析器确实定义了它,所以我尝试编译它:
dyn-72-33-132-199:Desktop bf$ gcc -o parser SimpleCalcParser.c
Undefined symbols:
"_antlr3CommonTokenStreamSourceNew", referenced from:
_main in ccn8ZVhk.o
"_antlr3ParserNewStream", referenced from:
_SimpleCalcParserNewSSD in ccn8ZVhk.o
"_SimpleCalcLexerNew", referenced from:
_main in ccn8ZVhk.o
"_antlr3AsciiFileStreamNew", referenced from:
_main in ccn8ZVhk.o
ld: symbol(s) not found
collect2: ld returned 1 exit status因此,有几个问题:
( 1)我做错了什么?我非常肯定库是被找到的,因为代码中还有其他的antlr函数和定义。我打gcc打错了吗?(我以前从未在命令行上编译过这么复杂的东西。)
2) ccn8ZVhk.o是什么?我可以看出它是一个对象代码文件,但在我的系统( locate和mdfind)上找不到它。
发布于 2009-12-03 08:55:19
您需要将lexer和解析器编译成同一个可执行文件;它们一起创建一个程序。试试这个:
gcc -o lexer SimpleCalcLexer.c SimpleCalcParser.c -lantlr3c该命令行将编译lexer和解析器,然后将结果链接到ANTLR库( "-lantlr3c“部分)。
对象文件ccn8ZVhk.o是运行时库的一部分,实际上称为main()。它不包含可使用的部件。
发布于 2009-12-07 04:37:20
如果您多次编译,您将看到每次都会更改对象代码文件名,因此我猜它们是在编译和链接最终目标之前使用的临时对象文件。我遇到了同样的问题,我尝试将架构指定为386和686。我正在尝试编译这个Python3语法文件的输出。CajunLuke,您能在它工作时发布用于编译的确切命令吗?下面是我所做的事情的一个例子:
WOPR:plex pokstad$ gcc -arch i686 -o lexer python3Lexer.c python3Parser.c -lantlr3c
Undefined symbols:
"_main", referenced from:
start in crt1.10.6.o
"_python3Lexer_syntetizeEmptyString", referenced from:
_mLEADING_WS in ccGDusga.o
"_python3Lexer_createLexerToken", referenced from:
_mCONTINUED_LINE in ccGDusga.o
_mLEADING_WS in ccGDusga.o
"_python3Lexer_initLexer", referenced from:
_python3LexerNewSSD in ccGDusga.o
ld: symbol(s) not found
collect2: ld returned 1 exit status另外,您对ANTLR3C运行时的编译是否与通常的“配置;make;make”不同?我试着使用64位选项进行编译,我也遇到了同样的问题。
https://stackoverflow.com/questions/1757357
复制相似问题