编译内核模块出现error: negative width in bit-field 错误
今天在写一个简单的内核测试模块的时候出现了一个挺奇怪的问题,网上查了一下也没人解决,自己试了好久终于解决了,所以分享出来供大家参考,先贴出源码:
/**********************************************
*文 件 名: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, 0777);
module_param_array(array, int, NULL, 0777); /*==============================================
*函 数 名: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 错误的更多相关文章
- ubuntu编译内核模块报错:Required key not available 的解决
系统为ubuntu18.04, 在编译内核模块insmod helloworld.ko的时候提示如下错误. 出现此问题的原因是,Ubuntu Kernel 使用 EFI_SECURE_BOOT_SIG ...
- OpenSceneGraph 编译 error LNK2019:unresolved external symbol 错误
在编译 OpenSceneGraph 的一个简单示例时, #include <osgViewer/Viewer> #include <osgDB/ReadFile> void ...
- maven 项目编译时候提示:Error building POM (may not be this project's POM).
编译时候提示Error building POM (may not be this project's POM)的错误,具体信息如下: [0] 'dependencies.dependency.ver ...
- wince6.0 编译报错:"error C2220: warning treated as error - no 'object' file generated"的解决办法
内容提要:wince6.0编译报错:"error C2220: warning treated as error - no 'object' file generated" 原因是 ...
- android stdio 编译项目报Error:Failed to find target with hash string 'android-24
android stdio 编译项目报Error:Failed to find target with hash string 'android-24 查看已有的SDK 设置项目的sdk为 25 an ...
- fedora/centos下gcc编译出现gcc: error trying to exec ‘cc1plus’: execvp: No such file or directory
fedora/centos下gcc编译出现gcc: error trying to exec 'cc1plus': execvp: No such file or directory解决办法 翻译自: ...
- 升级到JDK8,编译时发生 Error:java: java.lang.ExceptionInInitializerError
编译的时候出现这个问题.使用1.7的jdk没问题,但是由于po主的项目中,使用了java8编写的代码,解决java8兼容问题成为解决这个问题的首选方案. 这个日志太过简单,只告知一个异常信息,这个异常 ...
- python psutil 编译中断。 error: command 'gcc' failed with exit status 1
error info [root@chenbj psutil-2.0.0]# python setup.py install running install running bdist_egg run ...
- 在高通平台Android环境下编译内核模块【转】
本文转载自:http://blog.xeonxu.info/blog/2012/12/04/zai-gao-tong-ping-tai-androidhuan-jing-xia-bian-yi-nei ...
随机推荐
- oracle建索引的可选项
oracle中建索引可能大家都会,但是建索引是有几个选项参数却很少有人关注,在某些特殊环境下,可能会非常有用,下面一一说明: 1.NOSORT,记录排序可选项. 默认情况下,在表中创建索引的时候,会对 ...
- 架构设计:负载均衡层设计方案(7)——LVS + Keepalived + Nginx安装及配置
1.概述 上篇文章<架构设计:负载均衡层设计方案(6)——Nginx + Keepalived构建高可用的负载层>(http://blog.csdn.net/yinwenjie/artic ...
- LeetCode35 Search Insert Position
题目: Given a sorted array and a target value, return the index if the target is found. If not, return ...
- C语言第六节基本运算符
算术运算 C语言一共有34种运算符,包括了常见的加减乘除运算 加法运算+ 除开能做加法运算,还能表示正号:+5.+90 减法运算- 除开能做减法运算,还能表示符号:-10.-29 乘法运算* 注意符号 ...
- Balloon Comes!
Problem Description The contest starts now! How excited it is to see balloons floating around. You, ...
- 【开源项目13】Volley框架 以及 设置request超时时间
Volley提供了优美的框架,使android程序网络访问更容易.更快. Volley抽象实现了底层的HTTP Client库,我们不需关注HTTP Client细节,专注于写出更加漂亮.干净的RES ...
- JS 获取WEB请求路径
function getRealPath(){ //获取当前网址,如: http://localhost:8083/myproj/view/my.jsp var curWwwPa ...
- oracle PL/SQL(procedure language/SQL)程序设计之游标cursors
游标 Cursors--Conception 每一条被Oracle服务器执行的SQL语句都有一个独立的游标与之相关联:隐式游标 Implicit cursors: 用于所有的DML和PL/SQL的SE ...
- jQuery的deferred对象详解(一)
最近一段时间,都在研究jquery里面的$.Deffered对象,几天都搞不明白,其中源码的运行机制,网上查找了相关的资料,<jQuery的deferred对象详解>阮一峰老师的文章,里面 ...
- 剑指Offer05 用栈模拟队列
添加了模板类应用 /************************************************************************* > File Name: ...