包括glibtop在linux CPU负载

时间:2011-11-07 21:47:22

标签: linux glib

这是我的代码,看看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文件的路径!

2 个答案:

答案 0 :(得分:1)

gcc -I.

The manual说:

  

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

答案 1 :(得分:0)

我刚刚尝试过相同的代码,它就像一个魅力。

$ 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。