我正在尝试在Xcode中在线跟随CS50课程。我已经导入了cs50头文件。我可以使用printf,但是在调用GetInt时仍然出现错误。错误读取:

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


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

最佳答案

您需要在XCode中将cs50.c添加到构建目标。为此,请从“文件”菜单中选择“将文件添加到...”,然后选中所有目标的框。如果添加更多构建目标,请选择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.ccs50.h在同一目录中的cs50.c):

$ clang -o foo foo.c cs50.c
$ ./foo
Input number...
5
You typed the number 5

08-18 14:53
查看更多