阅读线无法正常工作

readline not working properly

当我 运行 Xcode 中的这段代码时,我的构建失败了。我从 The Big Nerd Ranch Guide to Obj-C 中得到了大块。我不得不稍微修改它(添加库 stdlib.h 和 readline/readline.h)它说构建失败,但我看不到任何错误。这个问题可能看起来像是重复的,并且在某种程度上是重复的,但即使在看到他们的解决方案并亲自尝试之后,我仍然会遇到错误。

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

int main(int argc, const char * argv[])
{
    printf("Who is cool? ");
    const char *name = readline(NULL);
    printf("%s is cool!\n\n", name);
    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)

this link中提到了类似的问题。您必须 link 在构建阶段将 libreadline.dylib 文件添加到您的项目中。