LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-22-2006, 12:55 AM   #1
lilili
Member
 
Registered: Jan 2006
Location: SantaBarbara
Distribution: Slackware 12.1
Posts: 196

Rep: Reputation: 30
undefined reference to readline


hello everyone
I've just install readline 5.1 tgz.
I have a c code with readline function in it.
I've #include <readline/readline.h> and #include <readline/history.h> but when I try to compile with gcc code.c -o code
gcc complains about undefined reference to readline

thank you
 
Old 10-22-2006, 09:40 AM   #2
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
I would suggest putting readline.h and history.h in /usr/include/ (not in /usr/inclue/readline/ - as I've assumed you've done).
Code:
#include <readline.h>
#include <history.h>
If that would cause problems (due to similarily named headers) use the double quotes and specify the absolute path:
Code:
#include "/usr/include/readline/readline.h"
#include "/usr/include/readline/history.h"
I am by no means a C/C++ programmer, but I don't see anything that could go horrifically wrong.

Last edited by indienick; 10-22-2006 at 09:42 AM.
 
Old 10-22-2006, 10:59 AM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,784

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
I think you just need to compile with gcc -lreadline code.c -o code
 
Old 10-22-2006, 02:27 PM   #4
lilili
Member
 
Registered: Jan 2006
Location: SantaBarbara
Distribution: Slackware 12.1
Posts: 196

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by indienick
I would suggest putting readline.h and history.h in /usr/include/ (not in /usr/inclue/readline/ - as I've assumed you've done).
Code:
#include <readline.h>
#include <history.h>
If that would cause problems (due to similarily named headers) use the double quotes and specify the absolute path:
Code:
#include "/usr/include/readline/readline.h"
#include "/usr/include/readline/history.h"
I am by no means a C/C++ programmer, but I don't see anything that could go horrifically wrong.

when I try both your suggestions it gives me the same complain, undefined reference to readline

Thank you
 
Old 10-22-2006, 02:28 PM   #5
lilili
Member
 
Registered: Jan 2006
Location: SantaBarbara
Distribution: Slackware 12.1
Posts: 196

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by ntubski
I think you just need to compile with gcc -lreadline code.c -o code
Here is my o/p when I try your solution
/usr/lib/gcc/i486-slackware-linux/3.4.5/../../../libreadline.so: undefined refer ence to `tgetnum'
/usr/lib/gcc/i486-slackware-linux/3.4.5/../../../libreadline.so: undefined refer ence to `tgoto'
/usr/lib/gcc/i486-slackware-linux/3.4.5/../../../libreadline.so: undefined refer ence to `tgetflag'
/usr/lib/gcc/i486-slackware-linux/3.4.5/../../../libreadline.so: undefined refer ence to `BC'
/usr/lib/gcc/i486-slackware-linux/3.4.5/../../../libreadline.so: undefined refer ence to `tputs'
/usr/lib/gcc/i486-slackware-linux/3.4.5/../../../libreadline.so: undefined refer ence to `PC'
/usr/lib/gcc/i486-slackware-linux/3.4.5/../../../libreadline.so: undefined refer ence to `tgetent'
/usr/lib/gcc/i486-slackware-linux/3.4.5/../../../libreadline.so: undefined refer ence to `UP'
/usr/lib/gcc/i486-slackware-linux/3.4.5/../../../libreadline.so: undefined refer ence to `tgetstr'
collect2: ld returned 1 exit status



Thank you
 
Old 10-22-2006, 09:21 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,784

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
According to my manpages those functions are part of the ncurses library. Do you have #include <curses.h> and #include <term.h>? Maybe try
gcc -lreadline -lncurses code.c -o code
 
Old 10-22-2006, 10:28 PM   #7
lilili
Member
 
Registered: Jan 2006
Location: SantaBarbara
Distribution: Slackware 12.1
Posts: 196

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by ntubski
According to my manpages those functions are part of the ncurses library. Do you have #include <curses.h> and #include <term.h>? Maybe try
gcc -lreadline -lncurses code.c -o code
ntubski, You are the man.
It works just like I want it.

Thank you very much
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Undefined reference, why? george_mercury Programming 4 05-07-2009 12:15 AM
undefined reference vkmgeek Programming 1 05-11-2006 06:37 AM
Undefined Reference ChemicalBurn Programming 2 02-14-2005 03:01 AM
undefined reference mp4-10 Programming 3 01-25-2005 12:38 PM
:undefined reference to 'gtk_main' The Yeti Lives Linux - Newbie 1 05-30-2003 03:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration