c - CS50 第 1 周类(class)中的未定义引用

标签 c cs50

<分区>

我注册了 CS50。我正在做第 1 周的项目。程序顶部的#include 应该已经定义了某些程序,例如 get_string、get_int 等...在我进入项目之前,我运行了一个简单的测试以确保一切正常。

#include <cs50.h>
#include <stdio.h>

int main(void)
    {
        printf("What is your name?\n");
        string x = get_string("x");
        printf("Hello, %x!");
    }  

我的代码在上面,下面是我不断收到的错误。

undefined reference to `get_string'
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)

当我输入 #include 时,这些错误不是已经被引用了吗?

最佳答案

那是链接器错误,不是编译器错误。问题是您包含了 cs50.h,它具有 get_string 的声明,但您没有包含具有其定义的库。要修复它,请在命令行中传递 -lcs50

关于c - CS50 第 1 周类(class)中的未定义引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57949078/

相关文章:

c - 如何对我的字符指针数组进行排序

c - c中的初始化是如何工作的?

c++ - C 风格字符串和 c++ std::string 的函数

c++ - 在c中将十六进制字符串转换为十进制字符串

c - 如何使用 make 构建 CS50 程序

c - 尝试声明字符串数组时出现段错误

CS50 Pset3 错误 : expected identifier or '('

循环时更改多维数组第二层的值

CS50 Pset3音乐最终计算

c - C语言中如何给字符串赋值