我尝试在Xcode 6中创建C库,但它在代码usleep(2*1000*1000);
上编译错误。为什么在Xcode 6中编译C库时,C99`中的函数'usleep'的隐式声明是无效的?
和错误日志
/Users/apk/Desktop/test/test.c:37:9: Implicit declaration of function 'usleep' is invalid in C99
与另一个是/Users/apk/Desktop/test/test.c:37:9: Declaration of 'usleep' must be imported from module 'Darwin.POSIX.unistd' before it is required
的代码test.c
的部分是这样的:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int test(const char* dest) {
...
usleep(2*1000*1000);
}
而且在test.h
代码如下所示:
#ifndef __TEST_H__
#define __TEST_H__
int test(const char* dest);
#endif
发生错误是因为找不到头文件<netinet/in.h>
?
还是我错过了什么?
在此先感谢。