如何添加Linux源代码全局变量?

发布于 2025-01-22 21:29:07 字数 275 浏览 2 评论 0原文

我面临的情况需要声明一个全局变量,以便每个文件源代码的每个文件都可以引用它。众所周知,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文