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 |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
11-24-2015, 12:41 PM
|
#1
|
Senior Member
Registered: May 2007
Posts: 1,393
Rep:
|
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 12:43 PM.
|
|
|
11-24-2015, 01:05 PM
|
#2
|
Senior Member
Registered: May 2007
Posts: 1,393
Original Poster
Rep:
|
Quote:
Originally Posted by dedec0
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
... :-/
|
|
|
11-24-2015, 01:27 PM
|
#3
|
Moderator
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,361
|
The Flex libs exist or you would not see the lex.yy.c produced.
Do this, it will build and work as expected...
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 01:37 PM.
|
|
1 members found this post helpful.
|
11-24-2015, 01:45 PM
|
#4
|
Senior Member
Registered: May 2007
Posts: 1,393
Original Poster
Rep:
|
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?
|
|
|
11-24-2015, 01:58 PM
|
#5
|
Moderator
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,361
|
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 03:26 PM.
Reason: tpos, typs, typos - updated to remove incorrect linker reference.
|
|
1 members found this post helpful.
|
11-24-2015, 05:50 PM
|
#6
|
Senior Member
Registered: May 2007
Posts: 1,393
Original Poster
Rep:
|
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 05:51 PM.
|
|
|
All times are GMT -5. The time now is 02:13 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|