编译文件时出现以下错误,但我已经加入了fcntl.h文件,
$ gcc -o open open.c
open.c: In function ‘main’:
open.c:25: error: ‘O_DIRECT’ undeclared (first use in this function)
open.c:25: error: (Each undeclared identifier is reported only once
open.c:25: error: for each function it appears in.)
open.c:25: error: ‘O_LARGEFILE’ undeclared (first use in this function)
后来发现是fcntl.h中
#ifdef __USE_GNU
# define O_DIRECT 040000 /* Direct disk access. */
# define O_DIRECTORY 0200000 /* Must be a directory. */
# define O_NOFOLLOW 0400000 /* Do not follow links. */
# define O_NOATIME 01000000 /* Do not set atime. */
#endif
|
原来是需要定义
__USE_GNU,不过编译是加入-D__USE_GNU也没用,结果一样,最后发现是在编译是加入-D_GNU_SOURCE就行了,比如:
gcc -o open open.c -D_GNU_SOURCE
|
阅读(6382) | 评论(0) | 转发(0) |