错误:未知types名称'布尔'

我下载了源代码,并想编译扫描仪的文件。 它产生这个错误:

[meepo@localhost cs143-pp1]$ gcc -o lex.yy.o lex.yy.c -ll In file included from scanner.l:15:0: scanner.h:59:5: error: unknown type name 'bool' In file included from scanner.l:16:0: utility.h:64:38: error: unknown type name 'bool' utility.h:74:1: error: unknown type name 'bool' In file included from scanner.l:17:0: errors.h:16:18: fatal error: string: No such file or directory compilation terminated. 

我试图用不同的编译器来编译它,但是却出现了不同的错误。

 [meepo@localhost cs143-pp1]$ g++ -o scan lex.yy.c -ll /usr/bin/ld: cannot find -ll collect2: ld returned 1 exit status 

我的os是3.0-ARCH,我不知道为什么发生这种情况。 我该如何解决这个错误?

C90不支持布尔数据types。

C99包括它包括:

 #include <stdbool.h> 

C99,如果你有

 #include <stdbool.h> 

基思汤普森

如果编译器不支持C99,则可以自己定义它:

 // file : myboolean.h #ifndef MYBOOLEAN_H #define MYBOOLEAN_H #define false 0 #define true 1 typedef int bool; // or #define bool int #endif 

只需添加以下内容:

 #define __USE_C99_MATH #include <stdbool.h> 

在你的代码中有一行#include <string> 。 这本身告诉你,该程序是用C ++编写的。 所以使用g++gcc

对于缺less的库:如果可以find名为libl.so的文件,则应该在文件系统中libl.so 。 使用locate命令,尝试/usr/lib/usr/local/lib/opt/flex/lib ,或使用蛮力find / | grep /libl find / | grep /libl

find该文件后,必须将该目录添加到编译器命令行中,例如:

 g++ -o scan lex.yy.c -L/opt/flex/lib -ll