在AIX6.1和GCC4.2下面使用libperfstat.h出现问题

fengzhw 2011-05-21 01:03:18
gcc aixcpu.c -o acpu -lperfstat
In file included from /usr/include/sys/corral.h:25,
from /usr/include/libperfstat.h:28,
from aixcpu.c:10:
/usr/include/netinet/in6_var.h:65: error: array type has incomplete element type

不过AIX自己的xlc是没问题的,上面的编译命令只要把gcc换成cc就可以通过。
上网搜了一些,都没明确说怎么解决。这里有ibm的人么,能帮着出个主意么?

不行就得周一联系ibm support了。


/*
** Samples, created by Qin BaoJun, to get the cpu status information
** libperfstat.a
** http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.basetechref/doc/basetrf1/perfstat_cputot.htm
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <libperfstat.h>

void dispcpu(perfstat_cpu_t *);
void dispcputotal(perfstat_cpu_total_t *);

int main(int argc, char **argv) {
int retcode, i;
perfstat_id_t *id;
perfstat_cpu_t *cpu;
perfstat_cpu_total_t *cputotal;

/* Get the system cpu information, actually is the average information */
cputotal = (perfstat_cpu_total_t *)malloc(sizeof(perfstat_cpu_total_t));
memset(cputotal, 0, sizeof(perfstat_cpu_total_t));
retcode = perfstat_cpu_total(NULL, cputotal, sizeof(perfstat_cpu_total_t), 1);

if (retcode == -1) {
printf("Failed to execute perfstat_cpu_total\n");
exit(1);
}

/* display */
printf("<============ CPU average information ============>\n");
dispcputotal(cputotal);

/* Get the indivadul cpu information */
id = (perfstat_id_t *)malloc(sizeof(perfstat_id_t));
strcpy(id->name, """");

cpu = (perfstat_cpu_t *)malloc(4*sizeof(perfstat_cpu_t));
memset(cpu, 0, 4*sizeof(perfstat_cpu_t));

retcode = perfstat_cpu(id, cpu, sizeof(perfstat_cpu_t), 4);
if (retcode < 0) {
printf("error number : %d, errno : %d\n", retcode, errno);
exit(0);
}

/* Just display */
printf("\n<======== Individual CPU information ========>\n");
for (i=0; i<retcode; i++, cpu++) {
printf("<======== Individual CPU %d information =======>\n",i);
dispcpu(cpu);
}

/* free the allocated memory */
free(id);
free(cpu);
free(cputotal);

return 0;
}

void dispcputotal(perfstat_cpu_total_t *pt) {
printf("CPU description: %s\nactived cpu : %d, configured cpu : %d, cpu frequency : %lluMhz\n", pt->description, pt->ncpus, pt->ncpus_cfg, pt->processorHZ/1000000);
printf("CPU user time : %llu\n", pt->user);
printf("CPU sys time : %llu\n", pt->sys);
printf("CPU idle time : %llu\n", pt->idle);
printf("CPU wait time : %llu\n", pt->wait);
printf("Context switch : %llu\n", pt->pswitch);
printf("System call : %llu\n", pt->syscall);
printf("System reading : %llu\n", pt->sysread);
printf("System write : %llu\n", pt->syswrite);
printf("System forks : %llu\n", pt->sysfork);
printf("Number of bytes read by system : %llu\n", pt->readch);
printf("Number of bytes written by system : %llu\n", pt->writech);

}

void dispcpu(perfstat_cpu_t *cpu) {
printf("CPU name : %s\n", cpu->name);
printf("CPU user time : %llu\n", cpu->user);
printf("CPU sys time : %llu\n", cpu->sys);
printf("CPU idle time : %llu\n", cpu->idle);
printf("CPU wait time : %llu\n", cpu->wait);
printf("Context switch : %llu\n", cpu->pswitch);
printf("System call : %llu\n", cpu->syscall);
printf("System reading : %llu\n", cpu->sysread);
printf("System write : %llu\n", cpu->syswrite);
printf("System forks : %llu\n", cpu->sysfork);
printf("Number of bytes read by system : %llu\n", cpu->readch);
printf("Number of bytes written by system : %llu\n", cpu->writech);

}
...全文
235 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
fengzhw 2011-05-24
  • 打赏
  • 举报
回复
谢谢!好使!
fengzhw 2011-05-23
  • 打赏
  • 举报
回复
那个改法我也搜到了,但是存在两个严重问题:
一、系统头文件可以随便改么?抛开权限问题,这个一致性问题就很严重;

二、为什么xlc好使,gcc就不好使?同样的程序在AIX 5.2上用GCC 4.0是没问题的。
xunxun 2011-05-23
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 fengzhw 的回复:]

看过了,没找到线索
[/Quote]
那到底是什么内容呢

Google了一下,说是把
in6_var.h中的

extern CONST struct protosw inet6sw[];

改为

extern CONST struct protosw *inet6sw[];
justkk 2011-05-23
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 fengzhw 的回复:]
看过了,没找到线索
[/Quote]
呵呵
sakidodo 2011-05-23
  • 打赏
  • 举报
回复
array type has incomplete element type
错误不是写的很清楚了吗
justkk 2011-05-23
  • 打赏
  • 举报
回复
试试包含sys/protosw.h

#include <sys/protosw.h>
fengzhw 2011-05-21
  • 打赏
  • 举报
回复
看过了,没找到线索
justkk 2011-05-21
  • 打赏
  • 举报
回复
看看文件/usr/include/netinet/in6_var.h 的65行是什么..

1,194

社区成员

发帖
与我相关
我的任务
社区描述
该论坛主要探讨IBM AIX平台的安装、部署、应用开发等话题,并为网友们提供自由交流的平台。
社区管理员
  • IBM AIX社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧