LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   flex problem: gcc, installed libraries, $LD_LIBRARY_PATH (https://www.linuxquestions.org/questions/linux-software-2/flex-problem-gcc-installed-libraries-%24ld_library_path-4175563756/)

dedec0 01-12-2016 05:51 PM

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?

Keith Hedger 01-12-2016 07:02 PM

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 ).

John VV 01-12-2016 09:29 PM

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

pan64 01-13-2016 03:30 AM

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)

dedec0 01-13-2016 04:02 AM

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.

dedec0 01-13-2016 04:17 AM

Quote:

Originally Posted by pan64 (Post 5477286)
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!

dedec0 01-13-2016 04:50 AM

Quote:

Originally Posted by Keith Hedger (Post 5477167)
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).


All times are GMT -5. The time now is 10:25 AM.