c - Linux:对 "sleep"的 undefined reference ,即使我包含了 unistd.h

标签 c linux ubuntu

尝试使用sleep()短暂暂停我的程序。 除非我“制作”我得到一个 undefined reference to sleep ,尽管我#include <unistd.h>在顶部。

In function `main':
[...]/source/ball.c:232: undefined reference to `sleep' 
[...]/source/ball.c:240: undefined reference to `sleep'
collect2: error: ld returned 1 exit status

我正在使用Linux。 有什么建议么? 谢谢

编辑:这不是重复的问题,因为每次询问此问题时,用户都在 Windows 上运行它。解决方案。对我来说,不仅仅是包含 Windows header 。

编辑(2):指向其他问题的链接对我没有帮助。这就是我发表新帖子的原因。我不在 Windows 上!!

最佳答案

这是一个链接器错误,而不是编译器错误(您可以从“ld returned 1 exit status”部分看到 - ld 是链接器)。因此 sleep 在 header 中声明,可以正常编译,但您需要确保在链接阶段包含正确的库/二进制文件。

关于c - Linux:对 "sleep"的 undefined reference ,即使我包含了 unistd.h,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50123629/

相关文章:

c - Linux C IPv6 原始套接字 - 告诉套接字不要分配流标签

linux - 如何清理 bash 中分隔符也在双引号内的 csv?

Java语音识别

macos - 在 macOS 上更改 libpcap 版本(Apple 删除了一项功能)

node.js - 在注册表中找不到 "dt~mocha"("npm")

c++ - 您建议使用什么方法在您正在构建的跨平台库中进行操作系统 API 调用?

c - 在 C 中使用 strcspn 和 fgets 的登录功能问题

c - 函数返回 char 指针

ELF 执行期间的 Linux 内存/磁盘行为

linux - Heroku toolbelt 安装后 "Warning! PATH is not properly set up"& "RVM is not a function"