This can happen if you have the readline library installed but cmake is linking the wrong one.
I had this error recently, and I found that the cmake was linking a different readline installed with anaconda3 rather than the one installed directly via brew. Removing anaconda fixed the issue.