Xcode cs50.h 中的 C 问题

标签 c xcode cs50

我正在尝试在 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.ccs50.hcs50.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/

相关文章:

xcode - 致命 : Not a git repository (or any of the parent directories): . git-Xcode 4.3 中的错误

objective-c - NSBox 对焦环?

swift - 在我的 xcode9 项目中导入 DisplaySwitcher - 不起作用

c - 如何打印某个字符和空格后的字符

c - 空指针作为参数 1 传递

c - 'o' = 'u' + 6,这不应该是 'o' = 'u' - 6 吗?数组的默认值也不为 0 吗?

我们可以说 "C language operators are polymorphic"吗?

c - VS 2010 中 realloc 的奇怪错误

c - 如何改进 C 程序中的拼写检查时间?

c - 循环数组,找到零,执行操作,停止