请问一个UNIX下的C程序,gcc 提示异常。谢谢了
请教一个UNIX下的C程序,gcc 提示错误。多谢了!
在《UNIX环境高级编程》中的一个小例题,无法编译成功。
源代码如下:
1 #include "include/apue.h"
2
3 int
4 main(void)
5 {
6 if (lseek(STDIN_FILENO, 0, SEEK_CUR) == -1)
7 printf("cannot seek\n");
8 else
9 printf("seek OK\n");
10 exit(0);
11 }
编译命令:gcc -Wall -o fig3.1 fig3.1.c
错误提示如下:
In file included from /usr/include/sys/types.h:18,
from include/apue.h:13,
from fig3.1.c:1:
/usr/include/sys/feature_tests.h:336:2: #error "Compiler or options invalid; UNIX 03 and POSIX.1-2001 application require the use of c99.
其中,当前目录是 /Desktop/apue,“gcc -Wall -o fig3.1 fig3.1.c”执行的目录也是/Desktop/apue;apue.h位于/Desktop/apue/include目录下。
/usr/include/sys/types.h:18(即types.h的第18行)为:#include <sys/feature_tests.h>
include/apue.h:13(即apue.h的第13行)为:#include <sys/types.h>
fig3.1.c:1(即fig3.1.c的第1行)为:#include "include/apue.h"
我怀疑问题出在apue.h这个包含文件中,因为如果把源代码中“#include "include/apue.h"”替换为:“#include <types.h>; #include <unistd.h>; #include <stdio.h>;”之后,就可以编译通过(lseek函数包含在types.h和unistd.h中;printf函数包含在stdio.h中。)。
问题出在哪里呢?apue.h这个头文件中也包含了types.h、unistd.h和stdio.h。
我的环境是solaris 10。
------解决方案--------------------
libapue.a 编译好了没有
建议自己去编译个libapue.a,考虑下作者提供的源代码编译
我做习题的时候都是这样编译的
gcc -Wall xxx.c ../libapue.a -xxx (我的libapue.a 库放在了父目录)
在《UNIX环境高级编程》中的一个小例题,无法编译成功。
源代码如下:
1 #include "include/apue.h"
2
3 int
4 main(void)
5 {
6 if (lseek(STDIN_FILENO, 0, SEEK_CUR) == -1)
7 printf("cannot seek\n");
8 else
9 printf("seek OK\n");
10 exit(0);
11 }
编译命令:gcc -Wall -o fig3.1 fig3.1.c
错误提示如下:
In file included from /usr/include/sys/types.h:18,
from include/apue.h:13,
from fig3.1.c:1:
/usr/include/sys/feature_tests.h:336:2: #error "Compiler or options invalid; UNIX 03 and POSIX.1-2001 application require the use of c99.
其中,当前目录是 /Desktop/apue,“gcc -Wall -o fig3.1 fig3.1.c”执行的目录也是/Desktop/apue;apue.h位于/Desktop/apue/include目录下。
/usr/include/sys/types.h:18(即types.h的第18行)为:#include <sys/feature_tests.h>
include/apue.h:13(即apue.h的第13行)为:#include <sys/types.h>
fig3.1.c:1(即fig3.1.c的第1行)为:#include "include/apue.h"
我怀疑问题出在apue.h这个包含文件中,因为如果把源代码中“#include "include/apue.h"”替换为:“#include <types.h>; #include <unistd.h>; #include <stdio.h>;”之后,就可以编译通过(lseek函数包含在types.h和unistd.h中;printf函数包含在stdio.h中。)。
问题出在哪里呢?apue.h这个头文件中也包含了types.h、unistd.h和stdio.h。
我的环境是solaris 10。
------解决方案--------------------
libapue.a 编译好了没有
建议自己去编译个libapue.a,考虑下作者提供的源代码编译
我做习题的时候都是这样编译的
gcc -Wall xxx.c ../libapue.a -xxx (我的libapue.a 库放在了父目录)