How to fix a missing ld library for -lfl while compiling?
Asked Answered
V

5

10

I am trying to translate my .spl file into a C file (because there is no compiler). I have an example "Hello World" .spl file, and I have downloaded the Shakespeare Programming Language .tar and extracted it, but I have no idea what to do next. I can't seem to find instructions in any documentation. Can anyone help?

Edit:

When I type make -f "Makefile", I get the following output:

bison --verbose -d grammar.y
gcc -O2 -Wall -c grammar.tab.c
gcc -O2 -Wall -c makescanner.c
gcc makescanner.o -O2 -Wall -o makescanner
./makescanner include > scanner.l
flex -Cem -t scanner.l > scanner.c
scanner.l:600: warning, rule cannot be matched
gcc -O2 -Wall -c scanner.c
<stdout>:5823: warning: ‘yyunput’ defined but not used
gcc -O2 -Wall -c strutils.c
gcc grammar.tab.o scanner.o strutils.o -O2 -Wall -lfl -o spl2c
ld: library not found for -lfl
collect2: ld returned 1 exit status
make: *** [spl2c] Error 1
Villus answered 17/4, 2013 at 2:23 Comment(0)
M
5

The error:

ld: library not found for -lfl

means that you've missing the library which is part of flex library.

To check if you've already flex library installed, you can look after it using locate:

locate libfl.a

OSX

If you don't have it, you can install install flex (if you're using brew):

brew install flex

If you still having the problems, you may try to pass the following variables manually during make, e.g.:

LDFLAGS="-L/usr/local/Cellar/flex/*/lib" CPPFLAGS="-I/usr/local/Cellar/flex/*/include" make -f "Makefile"

or:

MAKEFLAGS="-j8 -L/usr/local/Cellar/flex/*/lib -I/usr/local/Cellar/flex/*/include" make -f "Makefile"

eventually by modifying DYLD_FALLBACK_LIBRARY_PATH environment.

You can see which environment were passed by executing brew --env.

Note: Make sure that you'll change the paths according to your environment.

Related:

Linux

On most popular Linux distributions, you can install it by:

apt-get install flex

Related:


OS X (Homebrew)

Alternatively use Homebrew to install Shakespeare:

brew install shakespeare -v

Which should detect all your dependencies.

Meagher answered 29/11, 2013 at 11:7 Comment(0)
M
1

You want to run the file called "Makefile" with the command make -f "Makefile", and if you have the commands ar gcc flex ranlib tar bison in your terminal, you should be fine.
You can test if you have a command by typing its name and then --help into your terminal.

Then you can use spl2c (which has now appeared in your SPL folder) with your code to make a .c file, which you can then put into gcc with spl.h to make a .o file, which you can finally put into gcc again with libspl.a to make a final, compiled program.

Just in case, put the files into gcc like this:
First pass: gcc programname.c spl.h -o programname.o
Second pass: gcc programname.o libspl.a -o compiledprogramname

You can comment if you want more info, hopefully this helps (or even works).

Mating answered 17/4, 2013 at 12:18 Comment(3)
See edit in original post please. Bottom line is when I type spl2c after running the make -f "Makefile" I get a "Command not found" error.Villus
@Villus -lfl means libfl.*. Are you sure you have lex (as in gnu flex) installed? If you do, maybe reinstalling it would help? Or redownload libfl.*? You can search for libfl-dev to find it. Or just redownload lex.Mating
OK. I've got spl2c working. After I run ./spl2x <hello.spl> hello.c, I run gcc hello.c, I get "fatal error: spl.h: No such file or directory". I tried to change the statement #include <spl.h> to #include "spl.h", but then I get several errors such as "undefined reference to 'global_initialize'", and "undefined reference to 'initialize_character'". Any ideas?Villus
M
1

If you're using a Mac, apparently OSX doesn't include the necessary libraries for flex, and that is what is causing the error: library not found for -lfl

However, there is supposed to be an equivalent replacement you can use, you'll just need to change a line in the Makefile. You should change this line:

$(CC) $^ $(CCFLAGS) -ll -o $@

to this:

$(CC) $^ $(CCFLAGS) -lfl -o $@

After doing that, trying running make again and see if you get any better results.

Masquerade answered 4/5, 2013 at 3:1 Comment(1)
See my most recent comment to the answer above, perhaps you can help? Thank youVillus
B
1

The problem is that the Authors decided to link their program against the mostly useless libfl library, which is almost never needed, so not included in some flex distributions (in particlar, the one on MacOS).

It turns out that libfl only has two functions defined in it -- main and yywrap. The main in libfl is pretty much never used, and the yywrap might as well not be, because all it does is return 1.

It turns out you can fix the code easily enough:

  1. edit the file include/user_code_top.metaflex and add the line %option noyywrap to the end.

  2. edit the Makefile and remove the -lfl from the link line (just search for the string -lfl and remove those 4 characters wherever they appear)

Now you should be able to build it (though you may need to delete the file scanner.l if you previously ran make and got the failure, as the Makefile fails to detect that it need to be rebuilt after editing the metaflex file).

Beadsman answered 12/4, 2015 at 6:25 Comment(0)
K
0

Actually, I had the same problem on OS X Yosemite.

make -f "Makefile"
bison --verbose -d grammar.y
gcc -O2 -Wall -c grammar.tab.c
grammar.y:915:42: warning: illegal character encoding in string literal
      [-Winvalid-source-encoding]
  ...converter by Jon <C5>slund and Karl Hasselstr<F6>m.           *\n");
                      ^~~~                        ~~~~
1 warning generated.
gcc -O2 -Wall -c makescanner.c
gcc makescanner.o -O2 -Wall -o makescanner
./makescanner include > scanner.l
flex -Cem -t scanner.l > scanner.c
scanner.l:600: warning, rule cannot be matched
gcc -O2 -Wall -c scanner.c
<stdout>:5822:17: warning: unused function 'yyunput' [-Wunused-function]
    static void yyunput (int c, register char * yy_bp )
                ^
<stdout>:5867:16: warning: function 'input' is not needed and will not be
      emitted [-Wunneeded-internal-declaration]
    static int input  (void)
               ^
2 warnings generated.
gcc -O2 -Wall -c strutils.c
gcc grammar.tab.o scanner.o strutils.o -O2 -Wall -lfl -o spl2c
ld: library not found for -lfl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [spl2c] Error 1

Solution

I was able to make the "Makefile" after changing:

spl2c: grammar.tab.o scanner.o strutils.o
  $(CC) $^ $(CCFLAGS) -lfl -o $@

to

spl2c: grammar.tab.o scanner.o strutils.o
  $(CC) $^ $(CCFLAGS) -ll -o $@

In the meantime I installed the flex library, but I'm not sure whether it helped or not. In case my solution doesn't work without the flex library, you can simply install it using:

brew install flex

(Here is how to get the brew: http://brew.sh)

Kangaroo answered 11/4, 2015 at 23:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.