Hi all,

I've bought the book "Objective-C Programming - The Big Nerd Ranch Guide" and I'm running through the beginning chapters which just regard C.

I'm doing this on my laptop running linux as I don't have a Mac (yet).

I'm having trouble with this code:

#import <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>

int main(int argc, char * argv[]) {

    printf("Who is cool? ");
    const char *name = readline(NULL);
    printf("%s is cool!\n\n", name);

    return 0;
}

I'm compiling (attempting to) using this command:

gcc -lreadline -o Coolness main.c // "Coolness" being the name of the program in the book

I'm getting the following error when trying to compile:

main.c:1:2: warning: #import is a deprecated GCC extension [-Wdeprecated]
/tmp/ccjLJXtd.o: In function main': main.c:(.text+0x1d): undefined reference toreadline'
collect2: error: ld returned 1 exit status

I've been trying to look up a solution but have so far only managed to get as far as the compile command above, grabbing the readline includes and adding #include <readline.h> and <history.h> (though I'm not sure what history.h is for or if I need it).

Any assistance would be greatly appreciated.

Thanks

Your computer is probably missing the readline folder and associated header files and library files.

If you are trying to learn objective-c, are you sure you install the gcc-objc (objective-C) compiler/package on your system? Also, try replacing the line #import <stdio.h> with #include <stdio.h>

Ancient Dragon: The files were missing initially but I've installed them since. Otherwise the error would be along the lines of "readline.h doesn't exist/not found/ etc..."
rubberman: Yeah, I'd noticed that about import but it's just a warning so I'm ignoring it. The book used it so I went with it :)
The work I'm doing currently is just for C so I wouldn't have thought that I would need an Objective-C compiler for this part.
By the end of the week I'll have a Mac Mini and let XCode worry about linking libraries.

do those includes not require quotes rather than angle brackets?

but it's just a warning so I'm ignoring it.

You should never ignore warnings (except maybe in compiler-supplied header files) because 90% of the time they are really errors.

You should never ignore warnings (except maybe in compiler-supplied header files) because 90% of the time they are really errors.

Good advice. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.