【问题标题】:What does undefined symbols for architecture x86_64 mean in C?架构 x86_64 的未定义符号在 C 中是什么意思?
【发布时间】:2013-07-21 12:49:37
【问题描述】:

这是我的代码。

#include <stdio.h>

int main(){
int first;
int second;
int third;
float average=0.0;

    printf ("This program will find the average of 3 numbers.\n");
    delay(1000);
    printf ("Type the first number.\n");
    scanf ("%d", &first);
    printf ("Type the second number.\n");
    scanf ("%d", &second);
    printf ("Type the third number.\n");
    scanf ("%d", &third);
    average = (first+second+third)/2.0;
    printf ("The average of %d, %d, and %d is %.3f\n", first, second, third, average);

return (0);
}

当我使用 gcc 编译时说

Undefined symbols for architecture x86_64:
  "_delay", referenced from:
      _main in cc62F0GD.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

我是编码初学者。这是什么意思,我该如何解决?

【问题讨论】:

  • @H2CO3 不! delay() 有一些问题我在过去也遇到过问题,我不知道,但在 linux 上我们使用 sleep() ,以前(7-8 年前我什至习惯在 Redhat 中调用 delay())但是现在目前在我的 ubuntu 系统中我没有 delay() 它通常出现在窗口基础系统上的 dos.h
  • 即使我记得使用 stdlib.h 我现在尝试过但它不起作用。
  • @GrijeshChauhan 嗯?在 C 中,头文件与链接器错误无关。
  • @H2CO3 我的意思是完成回答这个问题,这是非常重要的,使用 gcc 使用 sleep() 就是这样......

标签: c gcc compiler-errors


【解决方案1】:

编辑

由于代码是在 linux 环境下运行的,您可以使用 sleep 代替 delay。头文件是unistd.h

【讨论】:

    【解决方案2】:

    您需要在代码中包含#include&lt;stdlib.h&gt; 文件以用于delay() 函数,它未在stdio.h 中定义

    但我建议不要使用它,而是使用大多数基于 Unix 的操作系统建议的 unsigned int sleep(unsigned int seconds); 函数来自 #include &lt;unistd.h&gt;

    read don't use delay()

    【讨论】:

    • 它在 stdlib.h girijesh
    • Girijesh 很抱歉,它似乎不起作用,我在涡轮增压期间使用过同样的东西。我猜 time.h 也支持该功能。
    • 我没有 turbo c,它在 Visual Studio 2010 上不起作用。我搜索并发现 dos.h 定义了延迟。但最好使用睡眠而不是忙等待延迟。感谢您的澄清。
    • 这就是我回答这个问题的原因,它让我想起了我刚从windos-98转到linux的日子。 -- 现在我不知道哪个是我认为 window-vista 最新的窗口
    【解决方案3】:

    使用 sleep() 代替 delay()

    EX : sleep(1) = 1 秒延迟

    【讨论】:

      【解决方案4】:

      这里你得到的错误是表单加载器

      ld: symbol(s) not found for architecture x86_64
      

      我不确定,但请检查您的可执行文件中存在的符号。

      使用 nm 命令检查可执行文件中存在的符号。

      http://linux.die.net/man/1/nm

      delay() 不支持在 GCC 中使用 sleep()

      http://pubs.opengroup.org/onlinepubs/009695399/functions/sleep.html

      【讨论】:

      • stdlib.h 不包含 delay()。
      • 你能发布stdlib.h的更新链接吗,因为我使用较新的c库延迟()不可用。
      • 没关系。很抱歉造成误解。
      猜你喜欢
      • 1970-01-01
      • 2012-01-16
      • 2016-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-11
      • 2015-06-15
      • 1970-01-01
      相关资源
      最近更新 更多