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’
[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…
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:
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’.