错误:未知类型名称“bool”

发布于 2024-12-15 17:24:17 字数 698 浏览 5 评论 0原文

我下载了源代码,想编译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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

淡忘如思 2024-12-22 17:24:17

就我而言,#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 to gcc-x64 in the C/C++ Extension Settings.

有木有妳兜一样 2024-12-22 17:24:17

C90 不支持布尔数据类型。

C99 确实包含了它,其中包括:

#include <stdbool.h>

C90 does not support the boolean data type.

C99 does include it with this include:

#include <stdbool.h>
心如狂蝶 2024-12-22 17:24:17

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

但注意这个定义会改变 ABI 用于 bool 类型,因此链接使用正确定义的 bool 编译的外部库可能会导致难以诊断的运行时错误)。

C99 does, if you have

#include <stdbool.h> 

If the compiler does not support C99, you can define it yourself:

// file : myboolean.h
#ifndef MYBOOLEAN_H
#define MYBOOLEAN_H

#define false 0
#define true 1
typedef int bool; // or #define bool int

#endif

(but note that this definition changes ABI for bool type so linking against external libraries which were compiled with properly defined bool may cause hard-to-diagnose runtime errors).

忱杏 2024-12-22 17:24:17

只需添加以下内容:

#define __USE_C99_MATH

#include <stdbool.h>

Just add the following:

#define __USE_C99_MATH

#include <stdbool.h>
只有影子陪我不离不弃 2024-12-22 17:24:17

代码中的某处有一行 #include。这本身就告诉您该程序是用 C++ 编写的。所以使用g++gcc更好。

对于丢失的库:您应该在文件系统中查找是否可以找到名为 libl.so 的文件。使用locate命令,尝试/usr/lib/usr/local/lib/opt/flex/lib code>,或者使用暴力破解 find / | grep /libl.

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

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

Somewhere in your code there is a line #include <string>. This by itself tells you that the program is written in C++. So using g++ is better than gcc.

For the missing library: you should look around in the file system if you can find a file called libl.so. Use the locate command, try /usr/lib, /usr/local/lib, /opt/flex/lib, or use the brute-force find / | grep /libl.

Once you have found the file, you have to add the directory to the compiler command line, for example:

g++ -o scan lex.yy.c -L/opt/flex/lib -ll
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文