CS50第1周课程中未定义的参考文献

时间:2019-09-16 00:08:07

标签: 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时,这些错误是否已被引用?

1 个答案:

答案 0 :(得分:2)

那是一个链接器错误,而不是编译器错误。问题在于您包括了cs50.h,它的声明为get_string,但是您没有包括具有其定义的库。要解决此问题,请在命令行中传递-lcs50