LinuxQuestions.org
Review your favorite Linux distribution.
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 01-12-2016, 04:51 PM   #1
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,340

Rep: Reputation: 51
Question flex problem: gcc, installed libraries, $LD_LIBRARY_PATH


I have downloaded and compiled the current flex, version 2.6.0.

I have installed in on an alternate folder, using a prefix passed to the configure script: /home/me/local.

Although the flex documentation I have read did not say it, I have changed my bashrc to add the lib subfolder where flex is installed: /home/me/local/lib/. Before doing this, the same problem happened, and I thought this could fix it.

Now I'll paste some terminal lines that speak well enough:

Code:
$ echo $LD_LIBRARY_PATH 
/home/me/local/lib

$ flex --version
flex 2.6.0

$ cat fb1-1.l 
/* fb1-1 just like unix wc */
/* the "%option noyywrap" was added to fix the error, but it just changed it. The LD error is kept. */
%{
int chars = 0;
int words = 0;
int lines = 0;
%}

%option noyywrap

%%

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

%%

int main()
{
  yylex();
  printf("%8d%8d%8d\n", lines, words, chars);
  return 0;
}

$ flex fb1-1.l 

$ # this is a wrong gcc compilation, we must link the file with flex library

$ gcc -Wall lex.yy.c 
lex.yy.c:1104: warning: ‘yyunput’ defined but not used
lex.yy.c:1149: warning: ‘input’ defined but not used

$ # but it worked?!

$ # now the right one, like the book instructs to do

$ gcc lex.yy.c -lfl

lex.yy.c:1104: warning: ‘yyunput’ defined but not used
lex.yy.c:1149: warning: ‘input’ defined but not used
/usr/bin/ld: cannot find -lfl
collect2: ld returned 1 exit status

$ # the installed flex libraries?

$ 'ls' /home/me/local/lib
libfl.a      libfl_pic.la    libfl_pic.so.2.0.0  libfl.so.2.0.0
libfl.la     libfl_pic.so    libfl.so		 liby.a
libfl_pic.a  libfl_pic.so.2  libfl.so.2
How can make this library folder exist for flex, gcc and LD?
 
Old 01-12-2016, 06:02 PM   #2
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 3,058

Rep: Reputation: 831Reputation: 831Reputation: 831Reputation: 831Reputation: 831Reputation: 831Reputation: 831
When installing libs to non standard places you need to add that path to /etc/ld.so.conf, then run ldconfig ( all as root of course ).
 
Old 01-12-2016, 08:29 PM   #3
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,589

Rep: Reputation: 2643Reputation: 2643Reputation: 2643Reputation: 2643Reputation: 2643Reputation: 2643Reputation: 2643Reputation: 2643Reputation: 2643Reputation: 2643Reputation: 2643
if this is all you got from the command
Code:
$ echo $LD_LIBRARY_PATH 
/home/me/local/lib
you have a MAJOR problem

that echo command SHOULD have returned " /usr/include " along with that

What Operating System are you using ?
and WHY not use your packagemanager for installing a BASIC part of the OS
 
Old 01-13-2016, 02:30 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 19,906

Rep: Reputation: 6741Reputation: 6741Reputation: 6741Reputation: 6741Reputation: 6741Reputation: 6741Reputation: 6741Reputation: 6741Reputation: 6741Reputation: 6741Reputation: 6741
gcc does not use either LD_LIBRARY_PATH or ldconfig during linking. You need to specify:
gcc gcc lex.yy.c -L<path-to-lib> -lfl


(LD_LIBRARY_PATH must not contain /usr/include anyway)
 
1 members found this post helpful.
Old 01-13-2016, 03:02 AM   #5
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,340

Original Poster
Rep: Reputation: 51
The option to compile and install from source must work (given some dependencies, for some), independently of the package being available or not on the OS. It is not magic (usually... hehe). And I like it.

There is a Debian, an Ubuntu (not current), and possibly a Mint will exist too. I prefer the Debian family members, but sometimes I have to use others.
 
Old 01-13-2016, 03:17 AM   #6
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,340

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by pan64 View Post
gcc does not use either LD_LIBRARY_PATH or ldconfig during linking. You need to specify:
gcc gcc lex.yy.c -L<path-to-lib> -lfl


(LD_LIBRARY_PATH must not contain /usr/include anyway)
I have added that folder option to my gcc alias:
alias gcc='gcc -ggdb -Wall -L/home/me/local/lib'

It solved the problem. Thank you very much!
 
Old 01-13-2016, 03:50 AM   #7
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,340

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by Keith Hedger View Post
When installing libs to non standard places you need to add that path to /etc/ld.so.conf, then run ldconfig ( all as root of course ).
Really? That's another option? :-/ As a developer, it is not so unusual that sometimes I use machines without root access (root tasks are slower, depends on others and I'm not allowed to do it).
 
  


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] Why fl library is missing when flex is installed? dedec0 Linux - Software 5 11-24-2015 05:50 PM
Slackware 13.37 no $LD_LIBRARY_PATH for shared libraries. Where is it? charging-ibis Slackware 4 11-28-2012 02:23 PM
makefile problem with gcc bison/flex on ubuntu garvey Linux - Software 0 03-16-2009 04:31 PM
Does LD_LIBRARY_PATH variable loads all shared libraries in the directory to ram babu198649 Linux - Newbie 5 06-27-2008 08:24 AM
Problem with linking libraries using gcc shortyzms Linux - Software 1 03-29-2004 08:13 PM

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

All times are GMT -5. The time now is 09:43 PM.

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