readline AWOL?
Roger Oberholtzer
roger at opq.se
Tue Nov 18 12:06:28 PST 2008
On Nov 18, 2008, at 2:05 PM, Dog Walker wrote:
> On Mon, Nov 17, 2008 at 12:40 PM, Jorge Almeida
> <jjalmeida at gmail.com> wrote:
>> Hello, C-wise people,
>>
>> Can someone understand this?
>>
>> $ cat readtest.c
>> #include <stdio.h>
>> #include <readline/history.h>
>> #include <readline/readline.h>
>> #define MAINPROMPT ">"
>> int main(int argc, char *argv[])
>> {
>> char *lp;
>> lp=readline(MAINPROMPT);
>> return 0;
>> }
>> $ gcc readtest.c
>> /tmp/cc88uLvp.o: In function `main':
>> readtest.c:(.text+0x19): undefined reference to `readline'
>> collect2: ld returned 1 exit status
>> $ ls /usr/include/readline
>> chardefs.h history.h keymaps.h readline.h rlconf.h
>> rlstdc.h
>> rltypedefs.h tilde.h
>>
>> Tested in Gentoo and in FC5.
>>
>>> From man 3 readline:
>>
>> SYNOPSIS
>> #include <stdio.h>
>> #include <readline/readline.h>
>> #include <readline/history.h>
>>
>> char *
>> readline (const char *prompt);
>>
>>
>
> I would try doing what it says, i.e., declaring the readline function
> before you use it:
>
> char *
> readline (const char *prompt);
> int main(int argc, char *argv[])
> {
> char *lp;
> lp=readline(MAINPROMPT);
> return 0;
> }
>
This is not what the error is complaining about. It is complaining
about something in a .o file. gcc will happily make a .o file without
a function prototype. But it will not make an executable without all
references being satisfied. And that is what is happening here. It is
very very very (times a big number) bad form to declare function
prototypes on your own that mask those in files you include. Unless
there is damned good reason. And it should be surrounded by #error
messages so you are reminded each time you compile that this is done.
>
Roger Oberholtzer
OPQ Systems / Ramböll RST
Ramböll Sverige AB
Kapellgränd 7
P.O. Box 4205
SE-102 65 Stockholm, Sweden
Office: Int +46 8-615 60 20
Mobile: Int +46 70-815 1696
And remember:
It is RSofT and there is always something under construction.
It is like talking about large city with all constructions finished.
Not impossible, but very unlikely.
More information about the Linux-users
mailing list