c - undefined reference to `readline' -
this question has reply here:
'undefined reference' errors when compiling against library 1 replyi'm having problem trying run gnu readline library sample code available in wikipedia. here goes:
#include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <readline/readline.h> #include <readline/history.h> int main() { char* input, shell_prompt[100]; // configure readline auto-complete paths when tab key hit. rl_bind_key('\t', rl_complete); for(;;) { // create prompt string user name , current working directory. snprintf(shell_prompt, sizeof(shell_prompt), "%s:%s $ ", getenv("user"), getcwd(null, 1024)); // display prompt , read input (n.b. input must freed after use)... input = readline(shell_prompt); // check eof. if (!input) break; // add together input history. add_history(input); // stuff... // free input. free(input); } }
i'm working on restricted environment readline not available, had download sources, compile , install home dir.
this construction within home directory:
.local ├── include │ └── readline │ ├── chardefs.h │ ├── history.h │ ├── keymaps.h │ ├── readline.h │ ├── rlconf.h │ ├── rlstdc.h │ ├── rltypedefs.h │ └── tilde.h └── lib ├── libhistory.a ├── libhistory.so -> libhistory.so.6 ├── libhistory.so.6 -> libhistory.so.6.2 ├── libhistory.so.6.2 ├── libreadline.a ├── libreadline.so -> libreadline.so.6 ├── libreadline.so.6 -> libreadline.so.6.2 └── libreadline.so.6.2
the problem is, when phone call gcc throws me error:
$ gcc hello.c -o hello_c.o -i /home/my-home-dir/.local/include /tmp/cckc236e.o: in function `main': hello.c:(.text+0xa): undefined reference `rl_complete' hello.c:(.text+0x14): undefined reference `rl_bind_key' hello.c:(.text+0x60): undefined reference `readline' hello.c:(.text+0x77): undefined reference `add_history' collect2: error: ld returned 1 exit status
there reply here, i'm not using netbeans , i'm not quite sure how specify path library on command line.
i tried tell linker libraries are, result still same:
$ gcc hello.c -o hello_c.o -i /home/my-home-dir/.local/include -xlinker "-l /home/my-home-dir/.local/lib" /tmp/cceiepmr.o: in function `main': hello.c:(.text+0xa): undefined reference `rl_complete' hello.c:(.text+0x14): undefined reference `rl_bind_key' hello.c:(.text+0x60): undefined reference `readline' hello.c:(.text+0x77): undefined reference `add_history' collect2: error: ld returned 1 exit status
any ideas might missing here?
you need link againts actual library using -lreadline in gcc arguments
c readline libreadline
No comments:
Post a Comment