LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-24-2015, 01:41 PM   #1
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,076

Rep: Reputation: 36
Question Why fl library is missing when flex is installed?


I'm making this from a Debian GNU/Linux 8.2 (jessie). I have this Flex source code:

Code:
/* igual o wc do Unix */
%{
int chars = 0;
int words = 0;
int lines = 0;
%}

%%

[a-zA-Z]+   { words++; chars += strlen(yytext); }
\n          { chars++; lines++; }
.           { chars++; }

%%

main(int argc, char **argv)
{

   yylex();
   printf("%8d %8d %8d\n", lines, words, chars);
}

I save and compile the above source code with flex source-code.l. No error is shown (which means no output except the c file. After this, the expected step to work is gcc -lfl lex.yy.c, but this gives:

Code:
/tmp/ccxXhigZ.o: In function `main':
lex.yy.c:(.text+0x1bcf): multiple definition of `main'
/usr/lib/x86_64-linux-gnu/libfl_pic.a(libmain.o):(.text.startup+0x0): first defined here
/tmp/ccxXhigZ.o: In function `yylex':
lex.yy.c:(.text+0x42d): undefined reference to `yywrap'
/tmp/ccxXhigZ.o: In function `input':
lex.yy.c:(.text+0xf6a): undefined reference to `yywrap'
collect2: error: ld returned 1 exit status
Shouldn't the fl library exist, since flex is installed? This error is not expected because I'm following these steps from a book about Flex and Bison... :-/

Last edited by dedec0; 11-24-2015 at 01:43 PM.
 
Old 11-24-2015, 02:05 PM   #2
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,076

Original Poster
Rep: Reputation: 36
Arrow

Quote:
Originally Posted by dedec0 View Post
I'm making this from a Debian GNU/Linux 8.2 (jessie). I have this Flex source code:

Code:
/* igual o wc do Unix */
%{
int chars = 0;
int words = 0;
int lines = 0;
%}

%%

[a-zA-Z]+   { words++; chars += strlen(yytext); }
\n          { chars++; lines++; }
.           { chars++; }

%%

main(int argc, char **argv)
{

   yylex();
   printf("%8d %8d %8d\n", lines, words, chars);
}

I save and compile the above source code with flex source-code.l. No error is shown (which means no output except the c file. After this, the expected step to work is gcc -lfl lex.yy.c, but this gives:

Code:
/tmp/ccxXhigZ.o: In function `main':
lex.yy.c:(.text+0x1bcf): multiple definition of `main'
/usr/lib/x86_64-linux-gnu/libfl_pic.a(libmain.o):(.text.startup+0x0): first defined here
/tmp/ccxXhigZ.o: In function `yylex':
lex.yy.c:(.text+0x42d): undefined reference to `yywrap'
/tmp/ccxXhigZ.o: In function `input':
lex.yy.c:(.text+0xf6a): undefined reference to `yywrap'
collect2: error: ld returned 1 exit status
Shouldn't the fl library exist, since flex is installed? This error is not expected because I'm following these steps from a book about Flex and Bison... :-/
In the meantime, playing with aptitude on that machine, I have put together a few more details. Installed packages:

- libfl-dev 2.5.39-8+b1
- flex 2.5.39-8+b1
- bison 3.0.2dfsg-2

... :-/
 
Old 11-24-2015, 02:27 PM   #3
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,510
Blog Entries: 11

Rep: Reputation: 3472Reputation: 3472Reputation: 3472Reputation: 3472Reputation: 3472Reputation: 3472Reputation: 3472Reputation: 3472Reputation: 3472Reputation: 3472Reputation: 3472
The Flex libs exist or you would not see the lex.yy.c produced.

Do this, it will build and work as expected...

Code:
gcc lex.yy.c -lfl
It is not a Flex problem, the gcc args are order dependent.

From man gcc:

Quote:
You can mix options and other arguments. For the most part, the order you use
doesn't matter. Order does matter when you use several options of the same kind;
for example, if you specify -L more than once, the directories are searched in
the order specified. Also, the placement of the -l option is significant.

Last edited by astrogeek; 11-24-2015 at 02:37 PM.
 
1 members found this post helpful.
Old 11-24-2015, 02:45 PM   #4
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,076

Original Poster
Rep: Reputation: 36
Thank you! Now it worked.

I did not know that. Can you explain me why this order works and the other don't? I would guess that the correct order should not work because the source contains "extern int yywrap (void );" and it does not exist (yet).

Or maybe I should think reversed for gcc arguments?
 
Old 11-24-2015, 02:58 PM   #5
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,510
Blog Entries: 11

Rep: Reputation: 3472Reputation: 3472Reputation: 3472Reputation: 3472Reputation: 3472Reputation: 3472Reputation: 3472Reputation: 3472Reputation: 3472Reputation: 3472Reputation: 3472
I do not really know the details of how gcc operates at this level, but when -l is called before the lex.yy.c file has been compiled, it of course invokes any defines, and undefs, applicable at that moment.

The immediate clue for me was the error messages...

Code:
/tmp/ccxXhigZ.o: In function `main':
lex.yy.c:(.text+0x1bcf): multiple definition of `main'
/usr/lib/x86_64-linux-gnu/libfl_pic.a(libmain.o):(.text.startup+0x0): first defined here
/tmp/ccxXhigZ.o: In function `yylex':
lex.yy.c:(.text+0x42d): undefined reference to `yywrap'
/tmp/ccxXhigZ.o: In function `input':
lex.yy.c:(.text+0xf6a): undefined reference to `yywrap'
collect2: error: ld returned 1 exit status
The main function from flex is only defined if you have not defined one, and yywrap is only generated in the lex.yy.c code.

Because the flex libs are loaded before your code is compiled, it defines the main function and sees no yywrap. The fix would be to load and compile those libraries after the lex.yy.c, and your own options, have been compiled into object format.

Glad that worked for you!

Last edited by astrogeek; 11-24-2015 at 04:26 PM. Reason: tpos, typs, typos - updated to remove incorrect linker reference.
 
1 members found this post helpful.
Old 11-24-2015, 06:50 PM   #6
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,076

Original Poster
Rep: Reputation: 36
Complex. I never heard that a library could change (or similar action) its content at compilation time. I imagined that all -lXYZ would search for some .o or .so, but not for source code with precompilation details like #defines that affect what happens and is present in the end.

The multiple main definition error was something that puzzled me, but I assumed it was any secondary effect for the library not being correctly present.

Last edited by dedec0; 11-24-2015 at 06:51 PM.
 
  


Reply

Tags
flex


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] configure script report missing ncurses library when it is already installed. dbrazeau Linux - Software 1 10-03-2013 04:48 PM
[SOLVED] ./configure problem for libsf library due to apparently missing libdb library. vectrum Linux - Software 6 08-05-2011 03:11 PM
ldd reports shared library missing, but library exists on disk athv_gr Linux - Newbie 7 05-13-2009 01:31 PM
install from source - unable to find the libcurl library - but library is installed pulper Linux - Newbie 2 02-23-2009 10:00 PM
Compiling Binutils on FC6, with bison en flex installed DeJoos Linux From Scratch 2 02-05-2007 11:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:30 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