programing

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

prostudy 2022. 5. 7. 09:35
반응형

오류: 알 수 없는 유형 이름 '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복구하기 어려운 런타임 오류를 일으킬 수 있음).

다음을 추가하십시오.

#define __USE_C99_MATH

#include <stdbool.h>

네 코드 어딘가에 줄이 있어#include <string>이것만으로도 프로그램은 C++로 쓰여져 있다는 것을 알 수 있다.그래서 사용g++보다 낫다gcc.

누락된 라이브러리의 경우: 파일 시스템에서 다음 파일을 찾을 수 있는지 확인하십시오.libl.so. 사용locate명령, 시도/usr/lib,/usr/local/lib,/opt/flex/lib, 또는 brute-force를 사용한다.find / | grep /libl.

파일을 찾았으면 다음과 같이 컴파일러 명령줄에 디렉터리를 추가하십시오.

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

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

반응형