如何添加Linux源代码全局变量?
我面临的情况需要声明一个全局变量,以便每个文件源代码的每个文件都可以引用它。众所周知,Linux是一个整体的内核,因此可以做到。因此,我将全局变量添加到init/main.c文件中。但是,当我在其他文件中使用extern ..
时,编译器说undefined Reference
。有帮助吗?
更新
更多的文件可以访问,越好。要更具体地,我要追踪某些函数的执行时间,因此我定义一个全局变量,每次函数执行时,都会添加一个。这是满足我需求的最直接方法。
I face a situation where I need to declare a global variable so every file of Linux source code can reference it. As much as I know, Linux is a Monolithic kernel, so this can be done. So I add the global variable to the init/main.c file. However, when I use extern ..
in other files, the compiler says undefined reference
. Any help?
Update
The more file can access, the better. To be more concrete, I'm tracing the execution times of certain function, so I define a global variable, everytime the function executes, I'll add one. This is the most straightforward way to meet my demand.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论