Can't link libreadline on Ubuntu 14.04
5,637
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
Related videos on Youtube
Author by
Eduardo Spremolla
Updated on September 18, 2022Comments
-
Eduardo Spremolla over 1 year
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
-
Eduardo Spremolla over 9 yearsHuge thanks. I tell thar shuld be a very stupid error.