Nice programing

오류 : 알 수없는 유형 이름 'bool'

nicepro 2020. 11. 19. 22:01
반응형

오류 : 알 수없는 유형 이름 'bool'


소스 코드를 다운로드하고 스캐너 파일을 컴파일하고 싶었습니다. 다음 오류가 발생합니다.

[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은 부울 데이터 유형을 지원하지 않습니다.

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

(그러나이 정의 유형에 대한 ABI변경 bool하므로 올바르게 정의 된 상태로 컴파일 된 외부 라이브러리에 대한 링크는 bool진단하기 어려운 런타임 오류를 유발할 수 있습니다.)


코드 어딘가에 한 줄이 #include <string>있습니다. 이것은 그 자체로 프로그램이 C ++로 작성되었음을 알려줍니다. 따라서 사용하는 g++것이 gcc.

누락 된 라이브러리의 경우 :라는 파일을 찾을 수 있으면 파일 시스템을 살펴 봐야합니다 libl.so. locate명령을 사용 하거나 try /usr/lib,, /usr/local/lib/opt/flex/lib사용하거나 brute-force를 사용하십시오 find / | grep /libl.

파일을 찾으면 컴파일러 명령 줄에 디렉토리를 추가해야합니다. 예를 들면 다음과 같습니다.

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

다음을 추가하십시오.

#define __USE_C99_MATH

#include <stdbool.h>

참고 URL : https://stackoverflow.com/questions/8133074/error-unknown-type-name-bool

반응형