HZ 变量未定义

发布于 2024-08-16 06:11:38 字数 233 浏览 2 评论 0原文

我现在正在尝试编译某人的代码,该人正在使用变量 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 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

北笙凉宸 2024-08-23 06:11:38

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 your CXXFLAGS variable. This will by no means mean that the program will actually work on OS X, only that it might compile.

禾厶谷欠 2024-08-23 06:11:38

在我的 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.

凡尘雨 2024-08-23 06:11:38

它可能来自命令行:

c++ -DHZ=1000 file.cpp -o file.o

很难说更多,没有更多细节。这是什么操作系统?

it might be expected to come from the command line:

c++ -DHZ=1000 file.cpp -o file.o

hard to say more w/o more details. what operating system is this?

薄情伤 2024-08-23 06:11:38

答案似乎不再与 Linux Kernel 5.8.0 相关 - 头文件 /usr/include/asm/param.h 中只有一行,如下所示。我不知道他们为什么这样做。

#include <asm-generic/param.h>

您将在 /usr/include/asm-generic/param.h 中找到 #define HZ。下面的代码可以在我的 Ubuntu 发行版中找到,它可能与 Linux 因为它是一个依赖于体系结构的值。

// ...
#ifndef HZ
#define HZ 100
#endif
// ....

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.

#include <asm-generic/param.h>

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.

// ...
#ifndef HZ
#define HZ 100
#endif
// ....
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文