2012-11-09 33 views
1

我想在Cygwin中編譯一個簡單的ANTLR3項目(使用C目標構建)。我已經使用標準./configuremakemake install方式安裝在C運行時庫和庫出現安裝成功(頭文件安裝在/cygdrive/e/cygwin/usr/local/include/和庫文件是/cygdrive/e/cygwin/usr/local/lib/無法在cygwin下編譯ANTLR3項目,在OSX上工作正常

當我使用g ++編譯(我使用C++爲項目的其餘部分 - C++目標不必產生的AST的能力),並且所有的編譯罰款的文件,但鏈接失敗時使用:

g++ -m32 -o compile Main.o Lexer.o Parser.o 

給出了錯誤

Main.o:Main.cpp:(.text+0xfc): undefined reference to `_antlr3AsciiFileStreamNew' 
Main.o:Main.cpp:(.text+0x12b): undefined reference to `_antlr3CommonTokenStreamSourceNew' 
/usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../../i686-pc-cygwin/bin/ld: Main.o: bad reloc address 0x0 in section `.ctors' 
collect2: ld returned 1 exit status 

添加-lantlr3c標誌該命令也不起作用,雖然錯誤是不同的:

/usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../../i686-pc-cygwin/bin/ld: cannot find -lantlr3c 
collect2: ld returned 1 exit status 
make: *** [compile] Error 1 

最後,保持庫文件的本地目錄,並使用'-L「標誌也沒有按」 t工作:

Main.o:Main.cpp:(.text+0xfc): undefined reference to `_antlr3AsciiFileStreamNew' 
Main.o:Main.cpp:(.text+0x12b): undefined reference to `_antlr3CommonTokenStreamSourceNew' 
/usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../../i686-pc-cygwin/bin/ld: Main.o: bad reloc address 0x0 in section `.ctors' 
collect2: ld returned 1 exit status 

第一個命令在OSX上正常工作。任何人有任何想法?我認爲這可能與Cygwin奇怪的文件結構/安裝位置的選擇有關,但我不確定。

回答

2

我成功地在cygwin下創建了python3grammar(由Ales Teska編譯),其中的C運行時名爲「libantlr3c-3.4」和gcc-mingw32(ver4.7.0),編號爲 。

命令:

gcc -m32 *.c output/*.c -Iinclude -I. -L. -lantlr3c -o py.exe 

對於該錯誤消息;對`_antlr3AsciiFileStreamNew'的未定義引用。

這篇文章可能會有所幫助: http://contrapunctus.net/blog/2012/antlr-c 這適用於ANTLR版本3.2(的debian穩定),但我今天還了解到有在最新的一些顯著C API的變化,3.4版。首先,antlr3AsciiFileStreamNew必須替換爲antlr3FileStreamNew(文件名,ANTLR3_ENC_8BIT)。

+0

是的,那篇文章很有用。最後我放棄了試圖讓它在cygwin上工作,只是在Ubuntu VM中工作。我會接受這個答案的基礎上,你提供的有關3.4的變化的信息是花了我很長時間才發現的。 –

相關問題