免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1757 | 回复: 2
打印 上一主题 下一主题

SOLARIS 10 的C程序编译问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-05-29 15:35 |只看该作者 |倒序浏览
-bash-3.00$ cc -o io io.c
"io.c", line 1: warning: invalid white space character in directive
"io.c", line 2: warning: invalid white space character in directive
"io.c", line 3: warning: invalid white space character in directive
"io.c", line 4: warning: invalid white space character in directive
"io.c", line 5: warning: invalid white space character in directive
"io.c", line 6: warning: invalid white space character in directive
Undefined                       first referenced
symbol                             in file
kstat_chain_update                  io.o
kstat_read                          io.o
kstat_open                          io.o
ld: fatal: Symbol referencing errors. No output written to io

代码:
#include <kstat.h>
#include <stdio.h>
#include <inttypes.h>
#include <unistd.h>
#include <string.h>
#define SLEEPTIME 5

unsigned int sleep(unsigned int);
void my_io_display(char *, char *, kstat_io_t);

int main(int argc, char *argv[])
{
                kstat_ctl_t *kc;
                kstat_t *ksp;
                kstat_io_t kio;
               
                kc = kstat_open();
               
               
                while(1) {
                                if(kstat_chain_update(kc))
                                fprintf(stderr, "<<State Changed>>n");
                                for (ksp = kc->kc_chain; ksp != NULL; ksp = ksp->ks_next) {
                                                if (ksp->ks_type == KSTAT_TYPE_IO && strcmp(ksp->ks_class,"disk") == 0) {
                                                                kstat_read(kc, ksp, &kio);
                                                                my_io_display(ksp->ks_name, ksp->ks_class, kio);
                                                }
                                }
                                sleep(SLEEPTIME);
                } /* while(1) */

}

void my_io_display(char *devname, char *class, kstat_io_t k)
{
printf("Name: %s Class: %sn",devname,class);
printf("tnumber of bytes read %lldn", k.nread);
printf("tnumber of bytes written %lldn", k.nwritten);
printf("tnumber of read operations %dn", k.reads);
printf("tnumber of write operations %dn", k.writes);
}

论坛徽章:
0
2 [报告]
发表于 2008-05-29 15:36 |只看该作者

回复 #1 LairaLee 的帖子

问题是:   
Undefined                       first referenced
symbol                             in file

是什么意思 如何修正

论坛徽章:
0
3 [报告]
发表于 2008-05-29 16:18 |只看该作者

回复 #2 LairaLee 的帖子

已经解决

编译是要添加 -lkstat  
cc io.c -lkstat

在MAN cc 的时候没有找到这个参数 在官方文档上找到!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP