预处理器如何解析Linux内核头文件的路径?

huangapple go评论68阅读模式
英文:

How does preprocessor resolve the path of linux kernel' head file?

问题

我是新手,正在尝试通过重新编译内核向Linux内核添加新的syscall。在阅读源代码时,我发现很难定位头文件的路径。

例如:

#include <linux/kernel.h>   /* for printk */
#include <linux/syscalls.h> /* for SYSCALL_DEFINE1 macro */

SYSCALL_DEFINE1(printmsg, int, i)
{
    printk(KERN_DEBUG "Hello! This is a msg %d", i);
    return 1;
}

这是我定制的系统调用之一。我编辑了kernel/文件夹中的MakeFile和syscall_64.tbl。重新编译后,它可以正常工作,没有编译错误。

但是,我的问题是预处理器如何解析类似&lt;linux/syscalls.h&gt;的路径。根据我以前的理解,预处理器应该到/usr/include文件夹中搜索。当然,在/usr/include没有linux/syscalls.h

我发现linux/syscalls.h实际上在Linux项目的include/linux/中。

我想知道是什么让预处理器在实际使用&lt;&gt;时在项目中搜索,就像使用include ""一样。

我想知道这是否是由于MakeFile的某部分?如果是的话,MakeFile中的哪个命令可以实现这一点?

感谢任何帮助,并请告诉我是否有什么地方我理解错了。

英文:

I am new to C programming language, and currently trying to add new syscall to Linux kernel by re-compiling the kernel.

When I read the source code, I found it very difficult to locate the path of head file.

For example:

#include &lt;linux/kernel.h&gt;   /* for printk */
#include &lt;linux/syscalls.h&gt; /* for SYSCALL_DEFINE1 macro */

SYSCALL_DEFINE1(printmsg, int, i)
{
    printk(KERN_DEBUG &quot;Hello! This is a msg %d&quot;, i);
    return 1;
}

This is one of my customized system calls. I edited the MakeFile in kernel/ folder and syscall_64.tbl . After re-compiling, it worked. No compiling error.

However, my problem now is how the preprocessor resolves the path like &lt;linux/syscalls.h&gt;. Based on my previous understanding, the preprocessor would go to the folder /usr/include for searching. Certainly, there is no linux/syscalls.h within /usr/include.

I found linux/syscalls.h is actually in linux's project include/linux/ .

I was wondering what makes the preprocessor search within the project just like include &quot; &quot; when it is actually using &lt;&gt;.

I was wondering if it is because of some part of MakeFile? If so, which command in MakeFile could make this happen?

Thank you for any help, and please let me know if I misunderstood something.

答案1

得分: 0

预处理器具有多个内置搜索路径(gpp -print-search-dirs),其他路径可以通过运行时的 -Idir 选项添加。

英文:

The pre-processor have a number of built-in search paths (gpp -print-search-dirs), and others can be added at run-time via the -Idir option.

huangapple
  • 本文由 发表于 2023年2月26日 21:49:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/75572439.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定