You are not logged in.

#1 2008-01-27 04:52:12

illuminati11_13
Member
Registered: 2007-05-28
Posts: 5

difficulty in compiling code using readline library

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

#2 2008-01-27 09:09:51

wuischke
Member
From: Suisse Romande
Registered: 2007-01-06
Posts: 630

Re: difficulty in compiling code using readline library

Compile it with the following command to link the readline library:

gcc hello.c -lreadline -o hello

Offline

#3 2008-01-27 14:59:17

illuminati11_13
Member
Registered: 2007-05-28
Posts: 5

Re: difficulty in compiling code using readline library

An here I was trying to link to the directory. XP

Thanks.

Offline

#4 2008-01-27 17:47:58

T-Dawg
Forum Fellow
From: Charlotte, NC
Registered: 2005-01-29
Posts: 2,736

Re: difficulty in compiling code using readline library

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

#5 2008-01-27 18:02:27

elgatofelix
Member
From: Chile
Registered: 2007-07-03
Posts: 137

Re: difficulty in compiling code using readline library

T-Dawg wrote:

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

Board footer

Powered by FluxBB