Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Compiler errors 如何在编译时修复-lfl缺少的ld库?_Compiler Errors_Compiler Construction_Dependencies_Bison_Flex Lexer - Fatal编程技术网

Compiler errors 如何在编译时修复-lfl缺少的ld库?

Compiler errors 如何在编译时修复-lfl缺少的ld库?,compiler-errors,compiler-construction,dependencies,bison,flex-lexer,Compiler Errors,Compiler Construction,Dependencies,Bison,Flex Lexer,我正在尝试将.spl文件转换为C文件(因为没有编译器)。我有一个示例“Hello World”.spl文件,我下载了.tar并解压缩了它,但我不知道下一步该怎么做。我似乎在任何文档中都找不到说明。有人能帮忙吗 编辑: 当我键入make-f“Makefile”时,我得到以下输出: bison --verbose -d grammar.y gcc -O2 -Wall -c grammar.tab.c gcc -O2 -Wall -c makescanner.c gcc makescanner.o -

我正在尝试将
.spl
文件转换为C文件(因为没有编译器)。我有一个示例“Hello World”.spl文件,我下载了
.tar
并解压缩了它,但我不知道下一步该怎么做。我似乎在任何文档中都找不到说明。有人能帮忙吗

编辑:

当我键入
make-f“Makefile”
时,我得到以下输出:

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
bison--verbose-d grammar.y
gcc-O2-Wall-c语法表.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:警告,无法匹配规则
gcc-O2-Wall-c扫描仪.c
:5823:警告:已定义但未使用“yyunput”
gcc-O2-墙体-c结构.c
gcc grammar.tab.o scanner.o strutils.o-O2-Wall-lfl-osp2c
ld:找不到-lfl的库
collect2:ld返回了1个退出状态
make:**[spl2c]错误1

您希望使用命令
make-f“Makefile”
运行名为“Makefile”的文件,如果您有命令
ar
gcc
flex
ranlib
tar
bison
在你的终点站,你应该很好
您可以通过在终端中键入命令名,然后输入
--help
来测试是否有命令

然后,您可以在代码中使用
spl2c
(它现在已经出现在您的SPL文件夹中)来生成一个.c文件,然后您可以使用SPL.h将其放入
gcc
中来生成一个.o文件,最后使用libspl.a将其再次放入
gcc
中来生成最终的编译程序

以防万一,将文件放入
gcc
中,如下所示:
第一遍:
gcc programname.c spl.h-o programname.o

第二遍:
gcc programname.o libspl.a-o compiledprogramname


如果您想了解更多信息,您可以发表评论,希望这会有所帮助(甚至有效)。

如果您使用的是Mac,显然OSX没有包含flex所需的库,这就是导致错误的原因:
库找不到-lfl

然而,应该有一个等价的替换,您可以使用,您只需要更改Makefile中的一行。您应该更改此行:

$(CC) $^ $(CCFLAGS) -ll -o $@
为此:

$(CC) $^ $(CCFLAGS) -lfl -o $@
完成此操作后,请再次尝试运行make,查看是否获得更好的结果。

错误:

ld:找不到-lfl的库

意味着你错过了图书馆,它是你的一部分

若要检查是否已安装flex library,可以使用查找:

locate libfl.a
OSX

如果没有,可以安装flex(如果使用):

如果仍然存在问题,您可以尝试在make期间手动传递以下变量,例如:

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

最终通过修改
DYLD\u FALLBACK\u LIBRARY\u路径
环境

您可以通过执行
brew--env
来查看传递的环境

注意:确保您将根据您的环境更改路径

相关的:

Linux

在大多数流行的Linux发行版上,您可以通过以下方式安装它:

apt-get install flex
相关的:


OSX(自制) 或者使用自制软件安装莎士比亚:

brew install shakespeare -v

这应该能检测到你所有的依赖关系。

事实上,我在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

与此同时,我安装了flex库,但我不确定它是否有用。如果我的解决方案在没有flex库的情况下无法运行,您只需使用以下方法安装:

brew install flex

(以下是如何获取brew的方法:)

问题是,作者决定将他们的程序与几乎毫无用处的libfl库相链接,而libfl库几乎从来都不需要,因此在一些flex发行版中没有包含(特别是MacOS上的版本)

原来libfl中只定义了两个函数--
main
yywrap
。libfl中的
main
几乎从未被使用过,而
yywrap
也可能没有被使用过,因为它只返回
1

事实证明,您可以非常轻松地修复代码:

  • 编辑文件
    include/user\u code\u top.metaflex
    ,并在末尾添加行
    %选项noyywrap

  • 编辑
    Makefile
    并从链接行中删除
    -lfl
    (只需搜索字符串
    -lfl
    ,并将这4个字符删除到它们出现的任何位置)


  • 现在,您应该能够构建它了(尽管如果您以前运行make并失败,您可能需要删除文件
    scanner.l
    ,因为Makefile在编辑metaflex文件后无法检测到需要重新构建)。

    请参见原始帖子中的编辑。底线是当我在运行make-f“Makefile”后键入spl2c时,我得到一个“Command not found”错误。@Skyler
    -lfl
    表示
    libfl.
    。你确定你已经安装了
    lex
    (就像在gnu-flex中一样)吗?如果你这样做了,也许重新安装会有帮助?或者重新下载
    libfl.*
    ?您可以搜索
    libfl dev
    来找到它。或者只是,好的。我已经开始工作了。在我运行./spl2x hello.c之后,我运行gcc hello.c,我得到“致命错误:spl.h:没有这样的文件或目录”。我试图将语句#include改为#include“spl.h”,但随后出现了一些错误,如“未定义对‘全局’初始化’的引用”和“未定义对‘初始化’字符的引用”。有什么想法吗?看看我最近对上述答案的评论,也许你能帮上忙?非常感谢。
    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
    
    spl2c: grammar.tab.o scanner.o strutils.o
      $(CC) $^ $(CCFLAGS) -lfl -o $@
    
    spl2c: grammar.tab.o scanner.o strutils.o
      $(CC) $^ $(CCFLAGS) -ll -o $@
    
    brew install flex