最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

encounter erros while compile the character driver module

工作和技术 crifan 2153浏览 0评论

when I compile the driver module of a quiet simple char device,the errors happen:
—————————————————————————————————————————-
crifan@crifan-desktop:~/driver/chardev$ gcc -O2 -DMODULE -D__KERNEL__ -c testCharDev.c
testCharDev.c:9:26: error: linux/module.h: No such file or directory
testCharDev.c:10:25: error: linux/sched.h: No such file or directory
testCharDev.c:11:52: error: linux/kernel.h: No such file or directory
testCharDev.c:12:24: error: linux/init.h: No such file or directory
testCharDev.c:14: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘test_llseek’
testCharDev.c:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘test_read’
testCharDev.c:16: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘test_write’
testCharDev.c:18: warning: ‘struct file’ declared inside parameter list
testCharDev.c:18: warning: its scope is only this definition or declaration, which is probably not what you want
testCharDev.c:18: warning: ‘struct inode’ declared inside parameter list
testCharDev.c:19: warning: ‘struct file’ declared inside parameter list
testCharDev.c:19: warning: ‘struct inode’ declared inside parameter list
testCharDev.c:20: warning: ‘struct file’ declared inside parameter list
testCharDev.c:20: warning: ‘struct inode’ declared inside parameter list
testCharDev.c:28: error: variable ‘test_fops’ has initializer but incomplete type
testCharDev.c:31: error: unknown field ‘owner’ specified in initializer
testCharDev.c:31: error: ‘THIS_MODULE’ undeclared here (not in a function)
testCharDev.c:31: warning: excess elements in struct initializer
testCharDev.c:31: warning: (near initialization for ‘test_fops’)
testCharDev.c:32: error: unknown field ‘llseek’ specified in initializer
testCharDev.c:32: error: ‘test_llseek’ undeclared here (not in a function)
testCharDev.c:32: warning: excess elements in struct initializer
testCharDev.c:32: warning: (near initialization for ‘test_fops’)
testCharDev.c:33: error: unknown field ‘read’ specified in initializer
testCharDev.c:33: error: ‘test_read’ undeclared here (not in a function)
testCharDev.c:33: warning: excess elements in struct initializer
testCharDev.c:33: warning: (near initialization for ‘test_fops’)
testCharDev.c:34: error: unknown field ‘write’ specified in initializer
testCharDev.c:34: error: ‘test_write’ undeclared here (not in a function)
testCharDev.c:34: warning: excess elements in struct initializer
testCharDev.c:34: warning: (near initialization for ‘test_fops’)
testCharDev.c:35: error: unknown field ‘ioctl’ specified in initializer
testCharDev.c:35: warning: excess elements in struct initializer
testCharDev.c:35: warning: (near initialization for ‘test_fops’)
testCharDev.c:36: error: unknown field ‘open’ specified in initializer
testCharDev.c:36: warning: excess elements in struct initializer
testCharDev.c:36: warning: (near initialization for ‘test_fops’)
testCharDev.c:37: error: unknown field ‘release’ specified in initializer
testCharDev.c:37: warning: excess elements in struct initializer
testCharDev.c:37: warning: (near initialization for ‘test_fops’)
testCharDev.c:41: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘test_llseek’
testCharDev.c:46: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘test_read’
testCharDev.c:62: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘test_write’
testCharDev.c:67: warning: ‘struct file’ declared inside parameter list
testCharDev.c:67: warning: ‘struct inode’ declared inside parameter list
testCharDev.c:68: error: conflicting types for ‘test_open’
testCharDev.c:18: error: previous declaration of ‘test_open’ was here
testCharDev.c: In function ‘test_open’:
testCharDev.c:69: error: ‘MOD_INC_USE_COUNT’ undeclared (first use in this function)
testCharDev.c:69: error: (Each undeclared identifier is reported only once
testCharDev.c:69: error: for each function it appears in.)
testCharDev.c: At top level:
testCharDev.c:73: warning: ‘struct file’ declared inside parameter list
testCharDev.c:73: warning: ‘struct inode’ declared inside parameter list
testCharDev.c:74: error: conflicting types for ‘test_release’
testCharDev.c:19: error: previous declaration of ‘test_release’ was here
testCharDev.c: In function ‘test_release’:
testCharDev.c:75: error: ‘MOD_DEC_USE_COUNT’ undeclared (first use in this function)
testCharDev.c: At top level:
testCharDev.c:79: warning: ‘struct file’ declared inside parameter list
testCharDev.c:79: warning: ‘struct inode’ declared inside parameter list
testCharDev.c:80: error: conflicting types for ‘test_ioctl’
testCharDev.c:20: error: previous declaration of ‘test_ioctl’ was here
testCharDev.c: In function ‘test_init’:
testCharDev.c:91: error: ‘KERN_ERR’ undeclared (first use in this function)
testCharDev.c:91: error: expected ‘)’ before string constant
testCharDev.c:95: error: expected ‘)’ before ‘DEVIVE_NAME’
—————————————————————————————————————————-

while I ecounter the problem like "error: expected declaration specifiers or ‘…’ before ‘size_t’" as following :
—————————————————————————————————————————-
crifan@crifan-desktop:~/driver/module$ make
gcc -DMODULE -D__KERNEL__ -O2 -I/usr/src/linux-headers-2.6.22-14/include -c module.c  
module.c:5:27: error: linux/module.h: No such file or directory
module.c:6:27: error: linux/config.h: No such file or directory
module.c:7:25: error: linux/init.h: No such file or directory
In file included from /usr/src/linux-headers-2.6.22-14/include/linux/kernel.h:11,
                 from module.c:8:
/usr/src/linux-headers-2.6.22-14/include/linux/linkage.h:4:25: error: asm/linkage.h: No such file or directory
In file included from /usr/src/linux-headers-2.6.22-14/include/linux/kernel.h:15,
                 from module.c:8:
/usr/src/linux-headers-2.6.22-14/include/linux/bitops.h:9:24: error: asm/bitops.h: No such file or directory
In file included from /usr/src/linux-headers-2.6.22-14/include/linux/kernel.h:16,
                 from module.c:8:
/usr/src/linux-headers-2.6.22-14/include/linux/log2.h:52: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘is_power_of_2’
In file included from module.c:8:
/usr/src/linux-headers-2.6.22-14/include/linux/kernel.h:18:21: error: asm/bug.h: No such file or directory
In file included from module.c:8:
/usr/src/linux-headers-2.6.22-14/include/linux/kernel.h:125: error: expected declaration specifiers or ‘…’ before ‘size_t’
/usr/src/linux-headers-2.6.22-14/include/linux/kernel.h:126: error: format string argument not a string type
/usr/src/linux-headers-2.6.22-14/include/linux/kernel.h:126: warning: conflicting types for built-in function ‘snprintf’
/usr/src/linux-headers-2.6.22-14/include/linux/kernel.h:127: error: expected declaration specifiers or ‘…’ before ‘size_t’
/usr/src/linux-headers-2.6.22-14/include/linux/kernel.h:128: warning: conflicting types for built-in function ‘vsnprintf’
/usr/src/linux-headers-2.6.22-14/include/linux/kernel.h:129: error: expected declaration specifiers or ‘…’ before ‘size_t’
/usr/src/linux-headers-2.6.22-14/include/linux/kernel.h:130: error: format string argument not a string type
/usr/src/linux-headers-2.6.22-14/include/linux/kernel.h:131: error: expected declaration specifiers or ‘…’ before ‘size_t’
/usr/src/linux-headers-2.6.22-14/include/linux/kernel.h:172: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘printk_timed_ratelimit’
/usr/src/linux-headers-2.6.22-14/include/linux/kernel.h:221: error: expected declaration specifiers or ‘…’ before ‘size_t’
/usr/src/linux-headers-2.6.22-14/include/linux/kernel.h:223: error: expected declaration specifiers or ‘…’ before ‘size_t’
/usr/src/linux-headers-2.6.22-14/include/linux/kernel.h:223: error: expected declaration specifiers or ‘…’ before ‘bool’
/usr/src/linux-headers-2.6.22-14/include/linux/kernel.h:226: error: expected declaration specifiers or ‘…’ before ‘size_t’
/usr/src/linux-headers-2.6.22-14/include/linux/kernel.h:226: error: expected declaration specifiers or ‘…’ before ‘bool’
/usr/src/linux-headers-2.6.22-14/include/linux/kernel.h:228: error: expected declaration specifiers or ‘…’ before ‘size_t’
module.c:19: warning: data definition has no type or storage class
module.c:19: warning: parameter names (without types) in function declaration
module.c:20: warning: data definition has no type or storage class
module.c:20: warning: parameter names (without types) in function declaration
make: *** [module.o] Error 1
—————————————————————————————————————————-
and my makefile (under Ubuntu system) is :
—————————————————————————————————————————-
SRC =module.c
OBJC_M =module.o
CC   =gcc
CFLAG=-DMODULE -D__KERNEL__ -O2
INCLUDE=/usr/src/linux-headers-2.6.22-14/include
$(OBJC_M):$(SRC)
    $(CC) $(CFLAG) -I$(INCLUDE) -c $(SRC) $(OBJC)
clean:
    rm -f *.o
—————————————————————————————————————————-
so I change the INCLUDE form
INCLUDE=/usr/src/linux-headers-2.6.22-14/include
to
INCLUDE=/usr/src/linux-headers-2.6.22-14-generic/include
—————————————————————————————————————————-
then solve the problem above ,like "expected declaration specifiers or ‘…’ before ‘size_t’"
—————————————————————————————————————————-

转载请注明:在路上 » encounter erros while compile the character driver module

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
79 queries in 0.174 seconds, using 22.16MB memory