syscalls.h出了什么问题?

20

我正在测试K&R C书籍中的一些代码示例,其中一个程序使用了 #include "syscalls.h",但编译器抱怨无法找到该文件。我应该用什么替代 syscalls.h?它已经被弃用了吗?

5个回答

10

你应该使用unistd.h代替。 查看手册以获取您尝试进行的调用,因为它是系统相关的并且可能会有所不同。


5
尝试包含 unistd.h。我在文档中看到,该头文件包含大多数系统调用。

4
尝试包含 sys/syscall.h
编辑:请注意,其他答案可能是您真正想要的,因为 unistd.h 对于大多数所需的系统调用都有封装。

4

man syscall 对于从事以下内容的人也会很有帮助:


- IT技术
syscall(SYS_ble)

manpages 4.04说:

   #define _GNU_SOURCE         /* See feature_test_macros(7) */
   #include <unistd.h>
   #include <sys/syscall.h>   /* For SYS_xxx definitions */

   long syscall(long number, ...);

Symbolic constants for system call numbers can be found in the header file <sys/syscall.h>.

在glibc中,您需要使用以下内容:
  • syscall函数需要使用unistd.h
  • SYS_宏需要使用sys/syscall.h
POSIX 7没有提到syscall ,因此这只是 glibc的扩展功能
值得注意的是,Ubuntu 16.04软件包libc6-dev 2.23两者都有。
/usr/include/syscall.h
/usr/include/sys/syscall.h

第一个只包含:

#include <sys/syscall.h>

这样可以让你在代码中使用:

#include <syscall.h>

但我无法找到任何文档,因此建议您仅使用文档中记录的#include <sys/syscall.h>


1

只需使用 #include <sys/syscall.h>

你使用的是哪个编译器?


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接