You are not logged in.
Hello,
I'm trying to get a program to use GNU readline and I'm having trouble getting it to compile.
The code I'm using is this:
#include <stdio.h>
#include <readline/readline.h>
int main(void)
{
char *line = readline("input: ");
return 0;
}
and the output from gcc is this:
/tmp/ccIU682D.o: In function `main':
hello.c:(.text+0x19): undefined reference to `readline'
collect2: ld returned 1 exit status
Now, I know that the readline.h header file is loading, because I am able to access enum's defined in it, but I can't use any of the functions or variables declared in it. It seems to be that these are all externs which suggests to me that the problem is that readline.h's own dependencies are what are failing to be loaded. (though I confess, it has been a while since I've done anything in C) Of course, this doesn't make sense because the readline library (which I installed through pacman) ought to be complete and not missing any files. But I don't know.
Any help or insight on this problem would be greatly appreciated, thanks.
Last edited by illuminati11_13 (2008-01-27 04:52:50)
Offline
Compile it with the following command to link the readline library:
gcc hello.c -lreadline -o hello
Offline
An here I was trying to link to the directory. XP
Thanks.
Offline
on a related note: is there a way to compile that library statically into the binary itself so that it is not dependent on that shared object?
Offline
on a related note: is there a way to compile that library statically into the binary itself so that it is not dependent on that shared object?
With -l flag the linker uses libreadline.so , with -static it will static link libreadline.a
Are u listening?
Offline