Click here to Skip to main content
15,921,577 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I implement history with readline and I have an error

code from user:
C++
#include<readline readline.h="">
#include<readline history.h="">
int main(){
char *line4;
while(1)
{
line4 = readline("Commander Shepard >");       
	add_history(line4);
}
}


What I have tried:

p.c:(.text+0x1478): undefined reference to `readline'
p.c:(.text+0x148e): undefined reference to `add_history'
Compailing with -lreadline or -readline I have another error
gcc: error: p: No such file or directory
Posted
Updated 25-Feb-16 1:19am
v3
Comments
Patrice T 25-Feb-16 6:14am    
And may be you also have some source code.
Laurentiu Bobora 25-Feb-16 6:25am    
#include<readline readline.h="">
#include<readline history.h="">
int main(){
char *line4;
while(1)
{
line4 = readline("Commander Shepard >");
add_history(line4);
}
}
Laurentiu Bobora 25-Feb-16 6:28am    
#include readline readline.h
#include readline history.h

Go to The GNU Readline Library[^], where everything is explained.
 
Share this answer
 
I assume that the library and the header files has been installed. Otherwise you would get a compiler error about missing include files.

You must pass the libraries after the source files when compiling and linking with a single line:
gcc -Wall source-file.cpp -lreadline -o program-name

The common gcc option sequence is then:

  • Compiler options like optimising and include pathes
  • Source files
  • Linker options like libraries and library pathes
  • Output

Or split compiling and linking into two commands:
gcc -Wall -c source-file.cpp
gcc source-file.o -lreadline -o program-name
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900