2011-11-07 1 views
0

리눅스에서 CPU로드를 확인하는 코드는 다음과 같습니다. 그러나 몇 가지 오류가 있습니다! glibtop을 다운로드하고 내 프로그램과 동일한 디렉토리에 넣으십시오. 그러나이 오류가 있습니다!리눅스 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â 

당신이 문제가 무엇인지 알고 내가 내 .H 파일의 경로를 리눅스 말해야한다 방법을 알고 dontr?!

+0

어떻게 gtop을 설치 했습니까? fedora를 사용한다면, yum을 사용하십시오. 데비안 또는 우분투 사용자 인 경우 apt-get을 사용하여 설치하십시오. –

답변

1

gcc -I.

The manual는 말한다 :

-I 디렉토리 헤더 파일을 검색 할 디렉토리 목록에 dir 디렉토리를 추가합니다.

+0

아니요 여전히 오류가 있습니다! :( – Sara

+0

gcc temp.c -I ~ Documents/libgtop-2.24.4 -o out.o이 작업을 수행했지만 작동하지 않습니다 !! – Sara

+0

여전히 같은 오류입니까? – themel

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 

그것은 libgtop2-dev 2.28.4-3 및 GCC 4.7.1과 데비안 불안정 AMD64에 있습니다.