2013-03-01 59 views
0

test1.c

#include <stdio.h> 

int main(void) { 
    printf("test\n"); 
    delay(1000); 
    printf("test2\n"); 
} 

当我尝试编译...Ç初学者:在一个简单的C程序

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

当然有前车之鉴在这里不能使用延迟()知道你的图书馆和什么链接等...我错过了什么?我正试图在OSX上执行此操作。

+0

几乎每个人的答案都在帮助我。多谢你们。睡觉很好。 – Beaon 2013-03-01 01:05:29

回答

4

在C中没有延迟功能,您必须使用sleepusleep,具体取决于您所在的操作系统。

+1

现在 - 等一下。有可能OP正在为另一个OSX系统读取一本书,在这种情况下,可能会有一个名为'delay'的函数。 POSIX中没有一个(这是OSX的主要基础)。 – 2013-03-01 00:55:32

1

迟迟未能下UNIX操作系统的替代方案是睡眠功能: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/sleep.3.html 做这样的事情:

#include <stdio.h> 
#include <unistd.h> 

int main(void) { 
    printf("test\n"); 
    usleep(1000); 
    printf("test2\n"); 
} 

如果值是1000个microsecondes。

+1

请注意,'usleep'需要*微秒*,而不是毫秒。 – 2013-03-01 00:56:40

+1

我认为你的意思是微秒。 – 2013-03-01 00:56:44

+1

编辑,对我的错误感到抱歉。 – Hulor 2013-03-01 00:58:26

0

延迟函数在Borland C编译器中工作。您必须使用dos.h头文件才能使用延迟。其他一些编译器如MinGW可能不支持这一点。