yacc로 생성된 c source를 compile시 에러

thisrule의 이미지

lex와 yacc를 공부하기 위해 인터넷 사이트에서 올려진 강좌를 따라하고 있습니다.
그런데 컴파일이 안됩니다.
y_calc.y가 있고, y_calc.l이 있습니다.

Quote:
[prompt]% yacc -d y_calc.y
[prompt]% lex y_calc.l
[prompt]% gcc -o calc y.tab.c lex.yy.c -ly -ll
/usr/bin/ld: cannot find -ly
collect2: ld returned 1 exit status

이렇게 되는군요. 즉 liby.a 라는 파일이 없다는 얘기인데 yacc 관련 라이브러리 같습니다.
그래서 이번에 -ly를 빼고 해보았습니다.
Quote:
[prompt]% gcc -o calc y.tab.c lex.yy.c -ll
gcc -o y_calc y.tab.c lex.yy.c -ll
/tmp/ccEqTYm5.o(.text+0x30a): In function `yyparse':
: undefined reference to `yyerror'
/tmp/ccEqTYm5.o(.text+0x5e9): In function `yyparse':
: undefined reference to `yyerror'
collect2: ld returned 1 exit status

결론적으로 yacc 관련 라이브러리가 필요하단 말이 됩니다.
yacc관련 rpm 설치정보에 원래 저 파일이 없습니다.
그래서 따로 파일을 구해보려는데 그것도 만만치 않네요.
전 레드햇9.0을 사용하는데 원래 저 파일이 없는건지...

즉, yacc로 생성된 c source를 gcc로 컴파일 하려는데 yacc 관련 라이브러리를 알수가 없어 컴파일이 되질 않습니다.
아시는 분들, 도와 주세요.

prolinko의 이미지

Linux에서 사용되는 yacc의 구현은 GNU에서 구현한 bison을 주로 사용합니다.

redhat계열의 경우 bison과 bison-devel이 나누어져 있어서 bison 프로그램만 깔리고 라이브러리는 안깔려있는 경우가 있더군요. bison-devel을 깔아주시고, -ly를 이용해서 컴파일해 보세요.

yum install bison-devel

yum이 없는 경우에는 알아서 bison과 bison-devel을 찾아다 까시길.

익명 사용자의 이미지

대충 아래와 같은 코딩으로 *.y를 작성하세요.

...
%%
...
%%
#include <stdio.h>

extern char yytext[];
extern int column;

int yyerror(char *s)
{
   fflush(stdout);
   printf("\n%*s\n%*s\n", column, "^", column, s);
}

int main()
{
   yyparse();
   return 0;
}

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.