在 Linux CPU 负载中包括 glibtop

发布于 2024-12-14 10:15:24 字数 1516 浏览 0 评论 0原文

这是我的代码,用于查看 Linux 中的 CPU 负载,但我有一些错误!我下载了 glibtop 并将其放在与我的程序相同的目录中,但我有这些错误!

    `#include "stdio.h"
     #include "glibtop.h"
     #include "glibtop/cpu.h"

     int main(){
     glibtop_init();
     glibtop_cpu cpu;
     glibtop_get_cpu (&cpu);
     printf("CPU TYPE INFORMATIONS \n\n"
     "Cpu Total : %ld \n"
     "Cpu User : %ld \n"
     "Cpu Nice : %ld \n"
     "Cpu Sys : %ld \n"
     "Cpu Idle : %ld \n"
     "Cpu Frequences : %ld \n",
     (unsigned long)cpu.total,
     (unsigned long)cpu.user,
     (unsigned long)cpu.nice,
     (unsigned long)cpu.sys,
     (unsigned long)cpu.idle,
     (unsigned long)cpu.frequency); 
     return 0;
     }`

我的错误是:

cpuLoad.c:2:21: error: glibtop.h: No such file or directory
In file included from cpuLoad.c:3:
glibtop/cpu.h:25:21: error: glibtop.h: No such file or directory
glibtop/cpu.h:26:28: error: glibtop/global.h: No such file or directory
In file included from cpuLoad.c:3:
glibtop/cpu.h:59: error: expected â=â, â,â, â;â, âasmâ or â__attribute__â before      âtypedefâ
glibtop/cpu.h:63: error: expected specifier-qualifier-list before âguint64â
glibtop/cpu.h:84: error: expected â)â before â*â token
glibtop/cpu.h:92: error: expected â)â before â*â token
glibtop/cpu.h:98: error: expected â)â before â*â token
glibtop/cpu.h:99: error: expected â)â before â*â token
cpuLoad.c:9: error: expected â=â, â,â, â;â, âasmâ or â__attribute__â before âintâ

你知道问题是什么吗?我不知道我应该如何告诉linux我的.h文件的路径!

Here is my code to see CPU load in linux but I have some errors! I downloaded glibtop and put it in same directory as my program is but I have these errors!

    `#include "stdio.h"
     #include "glibtop.h"
     #include "glibtop/cpu.h"

     int main(){
     glibtop_init();
     glibtop_cpu cpu;
     glibtop_get_cpu (&cpu);
     printf("CPU TYPE INFORMATIONS \n\n"
     "Cpu Total : %ld \n"
     "Cpu User : %ld \n"
     "Cpu Nice : %ld \n"
     "Cpu Sys : %ld \n"
     "Cpu Idle : %ld \n"
     "Cpu Frequences : %ld \n",
     (unsigned long)cpu.total,
     (unsigned long)cpu.user,
     (unsigned long)cpu.nice,
     (unsigned long)cpu.sys,
     (unsigned long)cpu.idle,
     (unsigned long)cpu.frequency); 
     return 0;
     }`

my errors are:

cpuLoad.c:2:21: error: glibtop.h: No such file or directory
In file included from cpuLoad.c:3:
glibtop/cpu.h:25:21: error: glibtop.h: No such file or directory
glibtop/cpu.h:26:28: error: glibtop/global.h: No such file or directory
In file included from cpuLoad.c:3:
glibtop/cpu.h:59: error: expected â=â, â,â, â;â, âasmâ or â__attribute__â before      âtypedefâ
glibtop/cpu.h:63: error: expected specifier-qualifier-list before âguint64â
glibtop/cpu.h:84: error: expected â)â before â*â token
glibtop/cpu.h:92: error: expected â)â before â*â token
glibtop/cpu.h:98: error: expected â)â before â*â token
glibtop/cpu.h:99: error: expected â)â before â*â token
cpuLoad.c:9: error: expected â=â, â,â, â;â, âasmâ or â__attribute__â before âintâ

do you know what is the problem?I dontr know how should I tell linux the path of my .h files!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

躲猫猫 2024-12-21 10:15:24

gcc -I.

手册说:

-I dir 将目录dir添加到要搜索头文件的目录列表中。

gcc -I. etc

The manual says:

-I dir Add the directory dir to the list of directories to be searched for header files.

丿*梦醉红颜 2024-12-21 10:15:24

我刚刚尝试了上面相同的代码,它的工作就像一个魅力。

$ gcc -Wall -g -Wextra main.c $(pkg-config --cflags --libs libgtop-2.0)
$ ./a.out
CPU TYPE INFORMATIONS

Cpu Total : 695672439
Cpu User : 4072158
Cpu Nice : 21564
Cpu Sys : 1523271
Cpu Idle : 687079036
Cpu Frequences : 100

它位于 Debian Unstable amd64 上,带有 libgtop2-dev 2.28.4-3 和 gcc 4.7.1。

I've just tried the same code above and it works like a charm.

$ gcc -Wall -g -Wextra main.c $(pkg-config --cflags --libs libgtop-2.0)
$ ./a.out
CPU TYPE INFORMATIONS

Cpu Total : 695672439
Cpu User : 4072158
Cpu Nice : 21564
Cpu Sys : 1523271
Cpu Idle : 687079036
Cpu Frequences : 100

It is on Debian Unstable amd64 with libgtop2-dev 2.28.4-3 and gcc 4.7.1.

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