user2607534
user2607534

Reputation: 221

What does undefined symbols for architecture x86_64 mean in C?

This is my code.

#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);
}

When I use gcc to compile it says

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

I am a beginner in coding. What does this mean and how do I fix it?

Upvotes: 0

Views: 1384

Answers (4)

Santhosh Pai
Santhosh Pai

Reputation: 2635

EDIT

Since the code is being run on linux environment you can use sleep instead of delay. The header file is unistd.h.

Upvotes: 1

sujin
sujin

Reputation: 2853

use sleep() instead of delay()

EX : sleep(1) = 1 second delay

Upvotes: 1

Grijesh Chauhan
Grijesh Chauhan

Reputation: 58291

You need to include #include<stdlib.h> file in your code for delay() function, its not defined in stdio.h

But I suggest don't use it, instead use what most Unix based operating system suggests unsigned int sleep(unsigned int seconds); function from #include <unistd.h>.

read don't use delay()

Upvotes: 1

pradipta
pradipta

Reputation: 1744

Here the error you got is form loader

ld: symbol(s) not found for architecture x86_64

I am not sure but check for the symbol present in your executable.

Use nm command to check the symbole present in your executable.

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

delay() in not supported in GCC use sleep()

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

Upvotes: 0

Related Questions