主题 : 关于调用系统API所要包含的头文件的问题 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 6476
精华: 0
发帖: 20
金钱: 195 两
威望: 96 点
综合积分: 40 分
注册时间: 2009-06-03
最后登录: 2011-04-14
楼主  发表于: 2009-09-04 15:32

 关于调用系统API所要包含的头文件的问题

我用的是mini2440的板子,一开始编译手册上的led测试程序,没有问题
后来想把led测试程序和qtopia带的hello程序结合起来做一个界面来控制led.就是这篇帖子里提到的http://www.aiothome.com/bbs/read.php?tid-2893.html
头文件包含的是led测试程序所包含的文件,可是编译出错‘open’was not declared in this scope
后来发现要包含另一个头文件fcntl.h,这我就有点奇怪了,为何在qtopia里调用就要多加这个头文件???????

不管怎么说,现在功能是实现了,就是有一个错误提示illegal instruction,现在还不知道原因

我这里有几个问题请教:
1.不同版本的linux,调用相同的系统API是否有可能包含的头文件不同?
2.能否介绍几本书,关于linux系统API的函数原型,相关参数的意义,以及如何来用这方面的
3.最后能否解释一下错误提示illegal instruction的原因,谢谢


*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2009-09-04 16:42
1.不同版本的linux,调用相同的系统API是否有可能包含的头文件不同?
2.能否介绍几本书,关于linux系统API的函数原型,相关参数的意义,以及如何来用这方面的

Linux上的"MSDN"就是man,要善于使用它。man 2 open ("2"表示open是系统调用)的结果应该会告诉你需要包含fcntl.h
至于为什么要包含fcntl.h, 因为它里面包含了open()的原型声明。这是4.3.2的arm-linux-gcc工具链里面的fcntl.h中open()的声明:
复制代码
  1. /* Open FILE and return a new file descriptor for it, or -1 on error.
  2.    OFLAG determines the type of access used.  If O_CREAT is on OFLAG,
  3.    the third argument is taken as a `mode_t', the mode of the created file.
  4.    This function is a cancellation point and therefore not marked with
  5.    __THROW.  */
  6. #ifndef __USE_FILE_OFFSET64
  7. extern int open (__const char *__file, int __oflag, ...) __nonnull ((1));
  8. #else
  9. # ifdef __REDIRECT
  10. extern int __REDIRECT (open, (__const char *__file, int __oflag, ...), open64)
  11.      __nonnull ((1));
  12. # else
  13. #  define open open64
  14. # endif
  15. #endif
  16. #ifdef __USE_LARGEFILE64
  17. extern int open64 (__const char *__file, int __oflag, ...) __nonnull ((1));
  18. #endif


3.最后能否解释一下错误提示illegal instruction的原因

这个可能是ABI不兼容引起的,比如用4.3.2的arm-linux-gcc (EABI)编译出的执行档在老的2.6.13内核系统(OABI)上执行就会出现这个错误。
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 6476
精华: 0
发帖: 20
金钱: 195 两
威望: 96 点
综合积分: 40 分
注册时间: 2009-06-03
最后登录: 2011-04-14
2楼  发表于: 2009-09-04 17:41
谢谢版主