LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1136|回复: 7

编译的时候有一个这样的warning,请问是什么意思?

[复制链接]
发表于 2004-2-16 17:15:14 | 显示全部楼层 |阅读模式
hello1.c:20: warning: implicit declaration of function `printk'

thx
发表于 2004-2-16 17:29:58 | 显示全部楼层
printk?printf?
发表于 2004-2-17 10:29:40 | 显示全部楼层

printk是内核中使用的函数,估计是变量的类型不正确。

up
 楼主| 发表于 2004-2-18 00:34:24 | 显示全部楼层
变量就只有一个字符串啊
不是和printf()一样的用法吗?
发表于 2004-2-18 14:24:48 | 显示全部楼层

把代码帖出来看看!

up
 楼主| 发表于 2004-2-18 21:28:45 | 显示全部楼层
/**************  hello.c  ****************/

#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif

#include <linux/module.h>

int init_module(void)
{
        printk("<1>Hello,world\n");
        return 0;
}

void cleanup_module(void)
{
        printk("<2>Goodbye\n");
}


/**************** makefile ***************/

DFLAGS = -D__KERNEL__ -DMODULE
CFLAGS = -O2 -g -Wall -Wstrict-prototypes -pipe -I/usr/src/linux-2.4/include

hello.o:hello.c
        gcc -c hello.c $(DFLAGS) $(CFLAGS) -o hello.o

clean:
        rm -f *.o


/**************** 编译时 ****************/

[root@zooka temp]# make
gcc -c hello1.c -D__KERNEL__ -DMODULE -O2 -g -Wall -Wstrict-prototypes -pipe -I/usr/src/linux-2.4/include -o hello.o
hello1.c: In function `init_module':
hello1.c:20: warning: implicit declaration of function `printk'


/*************  加载模块 **************/

[root@zooka temp]# insmod hello.o
Warning: loading hello.o will taint the kernel: no license
  See http://www.tux.org/lkml/#export-tainted for information about tainted modules
Module hello loaded, with warnings
 楼主| 发表于 2004-2-18 21:33:12 | 显示全部楼层
请指教,谢谢
发表于 2004-2-19 20:35:39 | 显示全部楼层

需要显式声明

需要显式声明,编译器编译的时候没找到声明,在用户态程序中也是如此。试着包含有该函数声明的内核头文件。本函数用法没错。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表