this may be a very stupid error, but can't find any reference in the web.

I try to compile this bare minimum readline example:

#include <stdio.h>
#include <malloc.h>
#include <readline/readline.h>

void main(void){

char *line;

while( 1==1 ){
    line=readline("enter text>");
    printf("text: %s <\n",line);
    free(line);
    }
}

and got this:

$>cc   -lreadline  read_test.c
/tmp/cc6JYBvf.o: In function `main':
read_test.c:(.text+0xe): undefined reference to `readline'
collect2: error: ld returned 1 exit status

The same code compiles perfect on my notebook Ubuntu 10.04.

also tryed:

cc -L/usr/lib/x86_64-linux-gnu  -lreadline read_test.c

or

cc -L/usr/lib/x86_64-linux-gnu  -lreadline -lncurses read_test.c

and several other variants with -m64 or --static

I have installed libreadline6-dev and libreadline5-dev.

Thanks in advance.

LALO

share|improve this question
up vote 2 down vote accepted

Put your arguments for the linker after instead of before your other arguments to gcc:

ek@Ilex:~/source$ gcc -lreadline read_test.c
/tmp/cc1IuVNQ.o: In function `main':
read_test.c:(.text+0xe): undefined reference to `readline'
collect2: error: ld returned 1 exit status
ek@Ilex:~/source$ gcc read_test.c -lreadline
ek@Ilex:~/source$ ./a.out
enter text>foo
text: foo ^C
share|improve this answer
    
Huge thanks. I tell thar shuld be a very stupid error. – Eduardo Spremolla Sep 14 '14 at 16:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.