readLine function not recognized

I’m using the latest copy of the book (just arrived today!) and I’m having an issue getting the examples of using readLine to work in XCode…

I’ve added the libreadline.dylib to my project in Build Phases, however when I try to compile even the simple example the editor complains:

const char *name = readline(NULL); Implicit declaration of function ‘readLine’ is invalid in C99 , Incompatible integer to pointer conversion initializing ‘const char *’ with an expression of type ‘int’

Any help would be appreciated!!

[quote]const char *name = readline(NULL); [color=#FF0000]Implicit declaration of function ‘readLine’ is invalid in C99[/color] , Incompatible integer to pointer conversion initializing ‘const char *’ with an expression of type 'int’[/quote]I don’t have the latest edition of the book, but that message is telling you that the compiler did not see the declaration of the readline function.
You need to include the header file which contains the declaration of that function, which I am guessing should look something like this:

const char * readline (void*); If you can’t find the header file, put the above declaration somewhere in the file before you invoke the function and compile to see if you get a linker error this time.

That function does not appear to be in the standard library. Did the book ask you to use that function?

Okay so since we aren’t covering headers yet, I added the function declaration before the main in my code and it works!!!

The book asked us to add the library via the Add Link binary with libraries in the Build Phases screen…but there was no declared include in the main file and no mention of adding the declaration as you suggest…

Thanks so much!!

The book did not specify it but my code worked if I included the following libraries:

#include <stdlib.h>
#include <readline/readline.h>

Same here. New version just came in the mail and I needed to add #include <readline/readline.h>

Same thing here. Just got the new revision of the book, and the header needed to be added. Ooops.

Indeed, this was my bad. The missing include of <readline/readline.h> is indeed the problem here. I’m sorry!

Had the same issue, working now thanks to adding the header file. Something else unusual is happening though with Xcode and I was wondering if it is happening for everyone. I’m running the who is cool code and in the console every letter I type appears twice. However, went it prints out my name it prints it correct. Here is a copy/paste from the console within Xcode:

[quote]
Who is cool?kkeevviinn

kevin is cool!

Program ended with exit code: 0[/quote]

I suppose I should have read the next page before posting. :laughing:

I had also forgotten to add the libreadline.dylib to my project in Build Phases also, so thanks all. Was wondering why I was getting strange error messages, and instant ‘Build Failed’.