我正在尝试在 Xcode 中学习 cs50 在线类(class)。我已经导入了cs50头文件。我可以使用 printf
,但在调用 GetInt
时仍然遇到错误。错误读取:
Apple Mach-O Linker (Id) Error "_GetInt", referenced from:
当然非常感谢任何帮助。谢谢。
最佳答案
您需要添加cs50.c
到 XCode 中的构建目标。为此,请从"file"菜单中选择“将文件添加到...”,然后勾选所有目标的框。如果添加更多构建目标,请选择 cs50.c
文件,然后在右侧检查器 Pane 中勾选新目标的框。
请注意,您还可以使用终端来使用命令行,如类(class)说明中所述。使用示例代码:
#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.h
和 cs50.c
位于同一目录中):
$ clang -o foo foo.c cs50.c
$ ./foo
Input number...
5
You typed the number 5
关于Xcode cs50.h 中的 C 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21958734/