경주란 빨리 달리는 사람들의 것이 아니라
       계속 뛰어가는 사람들의 것이다.
LinkTree🌲

카테고리 없음

[Bison] error: linker command failed with exit code 1

컴공희 2022. 11. 11. 12:19

GCC 작업 중 위와 같은 오류가 발생했습니다. 

제 노트북 환경은

Mac os

m1 입니다.  

window 환경에서는 정상 작동하는 데, 제 맥북에서는 작동하지 않았습니다.

 

오류 내용은 다음과 같았습니다. 

ld: warning: object file (/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libl.a(libmain.o)) was built for newer macOS version (13.0) than being linked (12.0)

ld: warning: object file (/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libl.a(libyywrap.o)) was built for newer macOS version (13.0) than being linked (12.0)

Undefined symbols for architecture arm64:

  "_yyerror", referenced from:

      _yyparse in pascal-like-e6095e.o

ld: symbol(s) not found for architecture arm64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

yyerror , yyparse 실행함에 있어서 오류가 발생한 것으로 보입니다.

오류가 발생하는 .y 파일안에

맨위에 

%{
/* Declaration  */
#include <stdio.h>
int yylex(void);
     int yyerror(char* s);

%}

를 추가하고

맨 밑줄에 

int main()
{
yyparse();

return 0;

}
int yyerror(char* s) {
printf("ERROR: %s\n", s);

return 0;

}


를 선언했습니다.

 

그렇게 진행하면 다음과 같이 정상적으로 컴파일 되었음을 확인할 수 있습니다. 같은 문제로 

고생하시는 분들도 참고하셨으면 좋겠습니다!