c - cs50 第 1 周课程中未定义的参考
问题描述
我报名参加了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
命令行。
推荐阅读
- tcp - Modbus TCP 远程端口
- r - 分类医学变量的数据汇总
- php - 全文搜索在 php mysql 中不起作用
- .net-core - 为什么内部模型没有更新
- node.js - 使用 Gitlab Runner 部署到 Digital Ocean 时,“docker pull”恰好需要 1 个参数错误
- php - PHP JSON数组访问
- cucumber - 是否可以与 webdriverio 并行运行 Cucumber 示例表?
- mongodb - 如何将等效的外键引入 MongoDB 文档?
- javascript - 防止来自 Chrome 开发者工具的 Javascript 变量更改和注入
- elixir - 有没有一种优雅的方式来返回 Elixir 管道中使用的函数的输入?