编译内核模块出现error: negative width in bit-field 错误
2013-10-27 12:34
483 查看
今天在写一个简单的内核测试模块的时候出现了一个挺奇怪的问题,网上查了一下也没人解决,自己试了好久终于解决了,所以分享出来供大家参考,先贴出源码:
make -C /lib/modules/3.2.0-29-generic-pae/build M=/home/linux/driver/experiment/ex04
make[1]: Entering directory `/usr/src/linux-headers-3.2.0-29-generic-pae'
LD /home/linux/driver/experiment/ex04/built-in.o
CC [M] /home/linux/driver/experiment/ex04/hello.o
/home/linux/driver/experiment/ex04/hello.c:24:1: error: negative width in bit-field ‘<anonymous>’
/home/linux/driver/experiment/ex04/hello.c:25:2: error: negative width in bit-field ‘<anonymous>’
make[2]: *** [/home/linux/driver/experiment/ex04/hello.o] Error 1
make[1]: *** [_module_/home/linux/driver/experiment/ex04] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.2.0-29-generic-pae'
make: *** [modules] Error 2
最后发现是module_param声明中有关权限的问题,这个权限不能是可写的.也就是说这个权限只能是rx的任意组合,5或4或1.因为模块运行在内核空间中,权限要求比较严格.
所以将
module_param(mystring, charp, 0777);
module_param_array(array, int, NULL, 0777);
改成
module_param(mystring, charp, 0555);
module_param_array(array, int, NULL, 0444);
就可以了.
/********************************************** *文 件 名:hello.c *文件描述:给模块传参 *创 建 人:Wang.J,2013.10.26 *版 本 号:0.1 *修改记录: **********************************************/ #include <linux/kernel.h> #include <linux/module.h> MODULE_LICENSE("Dual BSD/GPL"); //定义参数 int myint = 100; char *mystring = "This is name!"; short myshort = 10; long mylong = 100; int array[2] = {0}; //模块参数声明 module_param(myshort, short, 0555); module_param(myint, int, 0444); module_param(mylong, long, 0444); module_param(mystring, charp, 0111); module_param_array(array, int, NULL, 0000); /*============================================== *函 数 名:hello_module_init *参 数:void *功能描述:注册模块 *返 回 值:成功,返回0 *异 常: *创 建 人:Wang.J,2013.10.26 *修改记录: ==============================================*/ static int hello_module_init(void) { int ret = 0; int i; printk("This shirt is %d\n", myshort); printk("This int is %d\n", myint); printk("This long is %ld\n", mylong); printk("This string is %s\n", mystring); for (i = 0; i < sizeof(array)/sizeof(array[0]); i++) { printk("The %d of number is %d\n", i, array[i]); } return ret; } /*============================================== *函 数 名:hello_module_cleanup *参 数:void *功能描述:卸载函数 *返 回 值:void *异 常: *创 建 人:Wang.J,2013.10.26 *修改记录: ==============================================*/ static void hello_module_cleanup(void) { printk("hello_module_cleanup\n"); } module_init(hello_module_init); module_exit(hello_module_cleanup); //模块声明与描述 MODULE_AUTHOR("Wang.J"); MODULE_DESCRIPTION("hello This"); MODULE_ALIAS("别名"); MODULE_SUPPORTED_DEVICE("内存模拟");编译错误提示:
make -C /lib/modules/3.2.0-29-generic-pae/build M=/home/linux/driver/experiment/ex04
make[1]: Entering directory `/usr/src/linux-headers-3.2.0-29-generic-pae'
LD /home/linux/driver/experiment/ex04/built-in.o
CC [M] /home/linux/driver/experiment/ex04/hello.o
/home/linux/driver/experiment/ex04/hello.c:24:1: error: negative width in bit-field ‘<anonymous>’
/home/linux/driver/experiment/ex04/hello.c:25:2: error: negative width in bit-field ‘<anonymous>’
make[2]: *** [/home/linux/driver/experiment/ex04/hello.o] Error 1
make[1]: *** [_module_/home/linux/driver/experiment/ex04] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.2.0-29-generic-pae'
make: *** [modules] Error 2
最后发现是module_param声明中有关权限的问题,这个权限不能是可写的.也就是说这个权限只能是rx的任意组合,5或4或1.因为模块运行在内核空间中,权限要求比较严格.
所以将
module_param(mystring, charp, 0777);
module_param_array(array, int, NULL, 0777);
改成
module_param(mystring, charp, 0555);
module_param_array(array, int, NULL, 0444);
就可以了.
相关文章推荐
- 编译内核模块出现error: negative width in bit-field 错误
- 编译内核模块出现error: negative width in bit-field 错误
- error: negative width in bit-field ‘<anonymous>’
- 编译busybox的时候出现error: field 'in' has incomplete type
- linux 内核编译时出现scripts/sign-file.c:23:30: fatal error: openssl/opensslv.h错误的解决办法
- 【OC易错】Xcode5.0新建OS X下的cmd工程后出现编译错误clang: error: invalid version number in '-mmacosx-version-min=
- 编译php5.4的时候出现错误----configure: error: in `/usr/local/src/php540/php-5.4.0':
- Python csv模块读文件错误 _csv.Error: new-line character seen in unquoted field
- Linux驱动编程编译模块时出现 error:'TASK_NORMAL' undeclared (first use in this function
- linux 内核编译时出现scripts/sign-file.c:23:30: fatal error: openssl/opensslv.h错误的解决办法
- MySQL 编译出现 error: 'SSL_OP_NO_COMPRESSION' undeclared (first use in this function) 错误
- 在SSM框架中出现Field error in object 'xxx' on field 'XXX': rejected value [];错误
- 内核编译出现错误:[scripts/kconfig/dochecklxdialog] Error 1
- Keil4编译原子哥的SYSTEM出现错误error: #1113: Inline assembler not permitted when generating Thumb cod
- Qt5.x 编译QWebenginewidgets出现错误Project ERROR: Unknown module(s) in QT: webenginewidgets
- OpenCV打开摄像头出现运行错误OpenCV Error:Assertion failed (size.width>0&&size.height>0)in cv::imshow,……
- 编译Linux内核出现include/linux/compiler-gcc.h:106:30: fatal error: linux/compiler-gcc5.h错误
- linux 内核编译时出现scripts/sign-file.c:25:30: fatal error: openssl/opensslv.h错误的解决办法
- yaffs,linux3.11,内核编译时报错, error: unknown field 'readdir' specified in initializer
- 【SystemTap】 2.6.36 内核下运行SystemTap出现 error:‘param_ops_int64_t’ undeclared here (not in a function) 错误