I'm trying to compile a simple ANTLR3 project (built using the C target) in Cygwin. I've installed the C runtime library using the standard ./configure
, make
, make install
approach, and the libraries appeared to install successfully (the header files are installed in /cygdrive/e/cygwin/usr/local/include/
and the library file is in /cygdrive/e/cygwin/usr/local/lib/
.
When I compile with g++ (I am using c++ for the rest of the project - the C++ target does not have the ability to generate ASTs), the files all compile fine but the linking fails. Using:
g++ -m32 -o compile Main.o Lexer.o Parser.o
gives the error
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
Adding the -lantlr3c
flag to the command does not work either, although the error is different:
/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
Finally, keeping the library file in the local directory and using the `-L.' flag also doesn't work:
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
The first command works fine on OSX. Anyone got any ideas? I figure that it might have something to do with Cygwin's weird file structure/choice of install location but I'm not sure.
I succeeded to build python3grammar (by Ales Teska) under cygwin, with C runtime named "libantlr3c-3.4" and gcc-mingw32(ver4.7.0).
Command:
gcc -m32 *.c output/*.c -Iinclude -I. -L. -lantlr3c -o py.exe
For this error message; undefined reference to `_antlr3AsciiFileStreamNew'.
This article may be helpful: http://contrapunctus.net/blog/2012/antlr-c This works with ANTLR version 3.2 (debian stable), but I also learned today there are some significant C API changes in the latest, version 3.4. For one, antlr3AsciiFileStreamNew must be replaced with antlr3FileStreamNew(filename, ANTLR3_ENC_8BIT).