[질문]readline 함수 사용질문.

chxooi의 이미지

#include<stdio.h>

int main(void)
{
char *buffer;
char * s;
s = readline(buffer);
return 0;
}

물론 다 짠건 아니지만 readline 을 쓰기 위해 위와 같은 코드를 구현했습니다.
그런데 compile 을 하면,

gcc -o test test.c

/tmp/ccXxIWq9.o: In function 'main':
/tmp/ccXxIWq9.o:(.text+0x14):undefined reference to 'readline'
collect 2: ld returned 1 exit status

로 나옵니다.

undefined reference 라...readline 을 사용할 수 없는건가요?
아니면 원래 GNU C 에서 지원하는 default 함수가 아닌가요?

man 페이지에는 나와 있던데...양이 많아서 꼼꼼히 읽진 않았지만, 저렇게 쓰면 사용되어야 할꺼 같은데 에러 내용자체가 아예 참조가 안되는거 같아서 질문 드립니다.

답변 부탁 드려여..

alfalf의 이미지

#include <readline/readline.h>
#include <readline/history.h>

위의 두개 파일도 include 하셔야 합니다.

chxooi의 이미지

두개의 헤더 더했더니...

/tmp/cc01NZ78.o:In function 'main':
/tmp/cc01NZ78.o(.txt+0x14):undefined reference to 'readline'
collect2: ld returned 1 exit status

로 나오는군요.. 쩝..

Prentice의 이미지

(root로) ldconfig
gcc -o readlinetest test.c -lreadline

이렇게도 한번 해보세요.. : ) 참고로 테스트파일의 이름은 test로 하지 않으시는 것이 좋습니다.

chxooi의 이미지

gcc -o abcd test.c -lreadline
로 수행하니까...
/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../llibreadline.so:undefined reference to 'tgetnum'
/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../llibreadline.so:undefined reference to 'tgoto'
등이 쭈우욱~~~나오네요....

Prentice의 이미지

구글로 검색해봤더니 -ltermcap이나 -lncurses 둘 중 하나도 같이 붙여주셔야 한다고 나오는 것 같았습니다.

Google is your friend. :)

댓글 달기

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 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.