0

我正在尝试在 Xcode 中在线学习 cs50 课程。我已经导入了 cs50 头文件。我可以使用printf,但在调用GetInt. 错误读取:

Apple Mach-O Linker (Id) Error "_GetInt", referenced from:

任何帮助当然都非常感谢。谢谢你。

4

1 回答 1

0

您需要cs50.c在 XCode 中添加到您的构建目标。为此,请从“文件”菜单中选择“将文件添加到...”,然后勾选所有目标的复选框。如果您添加更多构建目标,请选择cs50.c文件并在右侧检查器窗格中勾选新目标的框。

请注意,您还可以按照课程说明中的说明使用终端来使用命令行。使用示例代码:

#include <stdio.h>
#include "cs50.h"
int main(void) {
    printf("Input number... \n");
    int x = GetInt();
    printf("You typed the number %d\n", x);
    return 0;
}

您可以按如下方式构建和运行它(假设代码与和foo.c位于同一目录中):cs50.hcs50.c

$ clang -o foo foo.c cs50.c
$ ./foo
Input number...
5
You typed the number 5
于 2014-02-22T19:03:44.987 回答