LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-19-2024, 10:16 PM   #1
ajiten
Member
 
Registered: Jun 2023
Posts: 377

Rep: Reputation: 4
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.
Attached Thumbnails
Click image for larger version

Name:	Screenshot (67).jpg
Views:	16
Size:	133.1 KB
ID:	42442   Click image for larger version

Name:	Screenshot (70).png
Views:	11
Size:	108.7 KB
ID:	42443  

Last edited by ajiten; 01-19-2024 at 10:36 PM.
 
Old 01-20-2024, 12:18 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,880
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
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.

You might want to check this topic which has a complete example linked in:
https://www.linuxquestions.org/quest...de-4175732020/

Last edited by NevemTeve; 01-20-2024 at 02:55 AM.
 
Old 01-20-2024, 02:56 AM   #3
ajiten
Member
 
Registered: Jun 2023
Posts: 377

Original Poster
Rep: Reputation: 4
Quote:
Originally Posted by NevemTeve View Post
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
Attached Thumbnails
Click image for larger version

Name:	Screenshot (72).jpg
Views:	4
Size:	171.4 KB
ID:	42444   Click image for larger version

Name:	Screenshot (74).png
Views:	6
Size:	198.2 KB
ID:	42445   Click image for larger version

Name:	Screenshot (78).png
Views:	6
Size:	205.3 KB
ID:	42446  

Last edited by ajiten; 01-20-2024 at 03:08 AM.
 
Old 01-20-2024, 03:05 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,029

Rep: Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343
it is not mentioned in that pdf, you need to use -lfl instead of -ll on cygwin. Probably.
 
Old 01-20-2024, 03:11 AM   #5
ajiten
Member
 
Registered: Jun 2023
Posts: 377

Original Poster
Rep: Reputation: 4
Quote:
Originally Posted by pan64 View Post
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'.
Attached Thumbnails
Click image for larger version

Name:	Screenshot (79).png
Views:	9
Size:	201.9 KB
ID:	42447  

Last edited by ajiten; 01-20-2024 at 03:14 AM.
 
Old 01-20-2024, 03:32 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,029

Rep: Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343
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.
 
Old 01-20-2024, 03:39 AM   #7
ajiten
Member
 
Registered: Jun 2023
Posts: 377

Original Poster
Rep: Reputation: 4
Quote:
Originally Posted by pan64 View Post
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.

Last edited by ajiten; 01-20-2024 at 03:51 AM.
 
Old 01-20-2024, 03:53 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,029

Rep: Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343
see the documentation cc -l<something> tells the linker to use a library named lib<something>.so. in general.
 
Old 01-20-2024, 04:17 AM   #9
ajiten
Member
 
Registered: Jun 2023
Posts: 377

Original Poster
Rep: Reputation: 4
Quote:
Originally Posted by pan64 View Post
see the documentation cc -l<something> tells the linker to use a library named lib<something>.so. in general.
Please tell what to fill in the '<something>' part.
 
Old 01-20-2024, 04:30 AM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,029

Rep: Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343
that is the name of the library. In your case it is either l or fl.
 
Old 01-20-2024, 06:23 AM   #11
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,880
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
@OP Please insert `int` before °main` that cannot be that hard.
When you have done that, I'll tell you the solution for the yywrap problem:
Code:
int yywrap(void) { return 1; }

Last edited by NevemTeve; 01-20-2024 at 07:26 AM.
 
1 members found this post helpful.
Old 01-20-2024, 07:54 AM   #12
ajiten
Member
 
Registered: Jun 2023
Posts: 377

Original Poster
Rep: Reputation: 4
Quote:
Originally Posted by NevemTeve View Post
@OP Please insert `int` before °main` that cannot be that hard.
Dear sir,
I did it, though otherwise it brings a warning.
I mean, not an error; unless you count warnings as errors.

P.S. Have sent a message to you on 16th, for which not sure why no response is coming.
 
Old 01-20-2024, 08:05 AM   #13
ajiten
Member
 
Registered: Jun 2023
Posts: 377

Original Poster
Rep: Reputation: 4
Quote:
Originally Posted by pan64 View Post
see the documentation cc -l<something> tells the linker to use a library named lib<something>.so. in general.
Sorry, but have got out of touch with cygwin.

I tried :
1. help cc,
2. info cc,
3. man -k cc,

though none worked. Please tell the correct command. Also, the command should be able to detail about the -lfl option too.
Attached Thumbnails
Click image for larger version

Name:	Screenshot (81).png
Views:	8
Size:	193.5 KB
ID:	42449  
 
Old 01-20-2024, 08:13 AM   #14
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,880
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
Off; no private messages, please
On: kindly read my previous posts: `-ll` is to be dropped; add this line into your program;
Code:
int yywrap(void) { return 1; }
PS: basic usage of the C-compiler should have been learnt already, but nonetheless here is a quickstart document: https://www3.ntu.edu.sg/home/ehchua/.../gcc_make.html

Last edited by NevemTeve; 01-20-2024 at 08:16 AM.
 
Old 01-20-2024, 10:04 AM   #15
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,786

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
Quote:
Originally Posted by pan64 View Post
see the documentation cc -l<something> tells the linker to use a library named lib<something>.so. in general.
In this case it is lib<something>.a, see https://cygwin.com/cygwin/packages/x...flex-2.6.4-0.1:

Quote:
2017-04-16 08:00 5470 usr/lib/libfl.a
Also https://gcc.gnu.org/onlinedocs/gcc-1...ndex-Libraries:
Quote:
-llibrary
-l library

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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How does a c program see the variable declared in a lex & yacc file carlnet Linux - General 2 04-11-2012 03:31 AM
implementing calculator program in lex and yacc but getting syntax error Avanti Linux - Newbie 1 10-27-2011 10:27 AM
LXer: XenSource's Levine And Citrix's Wasson Explain Future Virtualization Moves LXer Syndicated Linux News 0 08-24-2007 12:13 AM
Error in Makefile for Lex and Yacc oulevon Programming 2 10-24-2005 12:52 AM
Lex & yacc Programming in linux. hemanexp Linux - Software 2 01-07-2004 11:09 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration