Unable to resolve compilation error in c file, provided with the lex/yacc book by John Levine.
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Unable to resolve compilation error in c file, provided with the lex/yacc book by John Levine.
Am facing a never before seen error on compiling the first file in the code given for the sole book available for learning lex/yacc, i.e. the book by John Levine, Tony Mason, & Doug Brown; titled: Lex & Yacc, second edition.
The error is shown before, as given, at the top, in the page #7 (of the book).
Code:
$ cc lex.yy.c -o first -ll
ch1-02.l:38:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
38 | main()
| ^~~~
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: cannot find -ll: No such file or
directory
collect2: error: ld returned 1 exit status
The screenshot of the cygwin terminal is attached herewith too.
P.S. If you are feeling uncomfortable by a minor typo in page#7, though even I didn't; then the typo screen is attached herewith, and the errata page is here.
1. Use any text-editor to insert word `int` before `main`.
2. Do you a have a library called libl.so? If not, drop the `-ll` part.
Regarding your second point, please tell how to check for the presence of the same. Tried to check on cygwin, but it offers flex, and not lex; which as shown here should have instead libfl.so. The webpage, is shown in an attachment too.
The cygwin shows nothing like libfl, as shown in the attachment.
Kindly note that your first point failed to make any difference, except removing warning for the same effect; that gets introduced, when remove the return type of main (i.e., 'int'). This fact is shown in the last attachment.
Also, on removing the '-ll' part, it introduced new set of errors; stated below, as well as in the attachment.
Code:
$ cc lex.yy.c -o first
ch1-02.l:38:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
38 | int main()
| ^~~~
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: /tmp/ccJzPJqO.o:lex.yy.c:(.text+0x4ea): undefined reference to `yywrap'
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: /tmp/ccJzPJqO.o:lex.yy.c:(.text+0x110a): undefined reference to `yywrap'
collect2: error: ld returned 1 exit status
it is not mentioned in that pdf, you need to use -lfl instead of -ll on cygwin. Probably.
It works (as shown in the attachment), but not sure why it did.
Please help by detailing the reason. There is additional reason for asking as got the same as answer, when earlier failed, on some other site (that seems is inactive now, as coudl directly ask from one author there). The lack of reason, has created the same problem again (due to forgetting in a long span of time), which shouldn't have occurred, if had known the reason too for the choice of '-lfl'.
cygwin is an interesting thing, looks like a linux, but actually it is based on windows. It really just looks like linux, trying to be as close to it as possible, but there are a lot of "other" things going on behind the scenes, it's definitely not linux. That's why you will always find differences, for example the name of that library is not the same. But actually I don't know why it has been altered.
cygwin is an interesting thing, looks like a linux, but actually it is based on windows. It really just looks like linux, trying to be as close to it as possible, but there are a lot of "other" things going on behind the scenes, it's definitely not linux. That's why you will always find differences, for example the name of that library is not the same. But actually I don't know why it has been altered.
So, you mean that the option used for compiling, i.e. '-lfl' is actually a library file.
If yes, then am again sorry, as need to know how to locate the same.
In the attachment, there is curiously in the 'bin' folder, of cygwin installation; 'lex' as a system file, but nothing like 'lfl'.
However, there is a 'flex' application file, and 'flex++' system file, in the same folder. The last file with prefix, as 'flex' is 'flexlink' in the same folder.
P.S. Unable to attach the stated attachment, as inspite of trying to attach it multiple times, it does not show up.
Search the library named library when linking. (The second alternative with the library as a separate argument is only for POSIX compliance and is not recommended.)
The -l option is passed directly to the linker by GCC. Refer to your linker documentation for exact details. The general description below applies to the GNU linker.
The linker searches a standard list of directories for the library. The directories searched include several standard system directories plus any that you specify with -L.
Static libraries are archives of object files, and have file names like liblibrary.a. Some targets also support shared libraries, which typically have names like liblibrary.so. If both static and shared libraries are found, the linker gives preference to linking with the shared library unless the -static option is used.
It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, 'foo.o -lz bar.o' searches library 'z' after file foo.o but before bar.o. If bar.o refers to functions in 'z', those functions may not be loaded.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.