1
votes

When I try to run the following code, xcode throws the following error. What is causing this?

#import <Foundation/Foundation.h>
#include <readline/readline.h>

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

    @autoreleasepool {
        NSLog(@"What number would you like to count down by three from?");
        const char *countFrom = readline(NULL);
        NSString *result = [NSString stringWithUTF8String:countFrom];
        NSLog(@"Counting down from %@", result);
    }
    return 0;
}

Undefined symbols for architecture x86_64: "_readline", referenced from: _main in main.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

1
Where is readline implemented and how are you linking it?Phillip Mills
Not sure, going through a book on Objective-C and just typing the examples into Xcode on the mac.ThinkingInBits
I wouldn't down-vote this. There are various people asking this same question in various programming forums with no solid answers.ThinkingInBits
FWIW, I didn't down-vote. In fact, I was wondering why when I saw it had happened. (It's not a difficult question but it contained all the right information, unlike most of what I've read here this morning.)Phillip Mills
No worries, I wasn't under the assumption it was you :)ThinkingInBits

1 Answers

4
votes

Figured it out. Had to go into the Link Binary With Libraries section in the Build Phases section of project settings and include libreadline.dylib.