HZ 变量未定义
我现在正在尝试编译某人的代码,该人正在使用变量 HZ(我认为它代表 CPU 的赫兹),但编译器抱怨该变量未定义。我的猜测是这个人没有包含正确的头文件。
那么有谁知道HZ是在哪个头文件中定义的吗?
谢谢
编辑:编译适用于 Debian g++ 版本 4.3.2
我正在使用的设置 - OSX Leopard 10.5.8,g++ 版本 4.0.1 是失败的地方。
I'm trying to compile someone's code right now and the person is using a variable HZ (which I think stands for Hertz for the hertz of the cpu) but the compiler is complaining that the variable is not defined. My guess is that the person didn't include the correct header file.
So does anyone know which header file, HZ is defined in?
Thanks
Edit: Compilation works on Debian g++ version 4.3.2
The setup I'm using - OSX Leopard 10.5.8, g++ version 4.0.1 is where it fails.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Paul的答案是正确的,但我会扩展一下。
Linux 有一个编译时选项决定内核定时器的频率。在 HZ 定义的频率附近,内核调度程序将中断进程并开始其调度工作。 (一个相关的功能是 DynTicks 选项,它消除了 HZ 值,并根据工作负载更改中断频率。)最常见的设置是 100。高响应系统可能使用 1000。最近的内核版本使用默认值 250。系统计算工作负载繁重时可能会使用较小的值(以最小化调度程序的影响)。
因此,它是一个非常 Linux 特定的值,并且您只能在
/usr/include/asm/param.h
中找到它的定义,因为 100 是一个常见值,您只需将
-DHZ=100
添加到CXXFLAGS
变量中即可安全。这绝不意味着该程序实际上可以在 OS X 上运行,只是它可以编译。Paul's answer is correct, but I'll expand a little.
Linux has a compile-time option which determines the frequency of the kernel's timer. At approximately the frequency that HZ is defined to, the kernel scheduler will interrupt processes and begin its scheduling work. (A related feature is the DynTicks option, which elides the HZ value, and changes the interrupt frequency based on the workload.) The most common setting is 100. Highly responsive systems might use 1000. Recent kernel versions use a default of 250. Systems with heavy computational workloads might use a smaller value (to minimize the effect of the scheduler).
Thus it is a very Linux-specific value, and you'll only find it defined in
/usr/include/asm/param.h
Since 100 is a common value, you might be safe in simply adding
-DHZ=100
to yourCXXFLAGS
variable. This will by no means mean that the program will actually work on OS X, only that it might compile.在我的 Linux 机器上,它是在
/usr/include/asm/param.h:#define HZ 100
中定义的,我在 Mac OS X 机器上找不到任何定义。
On my Linux box, it's defined in
/usr/include/asm/param.h:#define HZ 100
I can't find a definition anywhere on my Mac OS X box.
它可能来自命令行:
很难说更多,没有更多细节。这是什么操作系统?
it might be expected to come from the command line:
hard to say more w/o more details. what operating system is this?
答案似乎不再与 Linux Kernel 5.8.0 相关 - 头文件
/usr/include/asm/param.h
中只有一行,如下所示。我不知道他们为什么这样做。您将在
/usr/include/asm-generic/param.h
中找到#define HZ
。下面的代码可以在我的 Ubuntu 发行版中找到,它可能与 Linux 因为它是一个依赖于体系结构的值。The answers seem no longer relevant on Linux Kernel 5.8.0 - There is only one line in the header file
/usr/include/asm/param.h
as shown below. I do not know why they did it that way.You'll find
#define HZ
in/usr/include/asm-generic/param.h
. The code below is found in my Ubuntu distribution and it is might be different than the one in Linux because it is an architecture-dependent value.