错误:未知类型名称“bool”
我下载了源代码,想编译scanner的文件。它产生了这个错误:
[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
我的操作系统是3.0-ARCH,我不知道为什么会发生这种情况。我该如何修复该错误?
I downloaded the source code and wanted to compile the file of scanner. It produces this error:
[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.
And I tried to use different complier to compile it, but it appeared different errors.
[meepo@localhost cs143-pp1]$ g++ -o scan lex.yy.c -ll
/usr/bin/ld: cannot find -ll
collect2: ld returned 1 exit status
My os is 3.0-ARCH, I don't know why this happened. How do I fix the error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
就我而言,
#include
还不够。解决方案是在 C/C++ 扩展设置中将
Intelli Sense Mode
设置为gcc-x64
。In my case the
#include <stdbool.h>
was not enough.The solution was to set
Intelli Sense Mode
togcc-x64
in the C/C++ Extension Settings.C90 不支持布尔数据类型。
C99 确实包含了它,其中包括:
C90 does not support the boolean data type.
C99 does include it with this include:
C99 可以,如果你的
编译器不支持 C99 的话,你可以自己定义一下:(
但注意这个定义会改变 ABI 用于
bool
类型,因此链接使用正确定义的bool
编译的外部库可能会导致难以诊断的运行时错误)。C99 does, if you have
If the compiler does not support C99, you can define it yourself:
(but note that this definition changes ABI for
bool
type so linking against external libraries which were compiled with properly definedbool
may cause hard-to-diagnose runtime errors).只需添加以下内容:
Just add the following:
代码中的某处有一行
#include
。这本身就告诉您该程序是用 C++ 编写的。所以使用g++
比gcc
更好。对于丢失的库:您应该在文件系统中查找是否可以找到名为
libl.so
的文件。使用locate
命令,尝试/usr/lib
、/usr/local/lib
、/opt/flex/lib
code>,或者使用暴力破解find / | grep /libl
.找到该文件后,必须将该目录添加到编译器命令行,例如:
Somewhere in your code there is a line
#include <string>
. This by itself tells you that the program is written in C++. So usingg++
is better thangcc
.For the missing library: you should look around in the file system if you can find a file called
libl.so
. Use thelocate
command, try/usr/lib
,/usr/local/lib
,/opt/flex/lib
, or use the brute-forcefind / | grep /libl
.Once you have found the file, you have to add the directory to the compiler command line, for example: