当前位置: 技术问答>linux和unix
今天用C++写Linux驱动,结果失败而归,大家帮我分析一下错误提示
来源: 互联网 发布时间:2016-07-09
本文导语: [root@localhost root]# cd /home/lys/Hello [root@localhost Hello]# g++ -c -I /usr/src/linux-2.4/include/ hello.cpp In file included from /usr/src/linux-2.4/include/linux/module.h:12, from hello.cpp:11: /usr/src/linux-2.4/include/linux/l...
[root@localhost root]# cd /home/lys/Hello
[root@localhost Hello]# g++ -c -I /usr/src/linux-2.4/include/ hello.cpp
In file included from /usr/src/linux-2.4/include/linux/module.h:12,
from hello.cpp:11:
/usr/src/linux-2.4/include/linux/list.h: In function `void
list_del(list_head*)':
/usr/src/linux-2.4/include/linux/list.h:94: invalid conversion from `void*' to
`list_head*'
/usr/src/linux-2.4/include/linux/list.h:95: invalid conversion from `void*' to
`list_head*'
In file included from /usr/src/linux-2.4/include/linux/fs.h:12,
from /usr/src/linux-2.4/include/linux/capability.h:17,
from /usr/src/linux-2.4/include/linux/binfmts.h:4,
from /usr/src/linux-2.4/include/linux/sched.h:10,
from /usr/src/linux-2.4/include/linux/mm.h:22,
from /usr/src/linux-2.4/include/linux/slab.h:14,
from hello.cpp:15:
/usr/src/linux-2.4/include/linux/wait.h: In function `void
init_waitqueue_head(wait_queue_head_t*)':
/usr/src/linux-2.4/include/linux/wait.h:165: parse error before `}' token
/usr/src/linux-2.4/include/linux/wait.h:165: excess elements in aggregate
initializer
In file included from /usr/src/linux-2.4/include/asm/semaphore.h:39,
from /usr/src/linux-2.4/include/linux/fs.h:200,
from /usr/src/linux-2.4/include/linux/capability.h:17,
from /usr/src/linux-2.4/include/linux/binfmts.h:4,
from /usr/src/linux-2.4/include/linux/sched.h:10,
from /usr/src/linux-2.4/include/linux/mm.h:22,
from /usr/src/linux-2.4/include/linux/slab.h:14,
from hello.cpp:15:
/usr/src/linux-2.4/include/asm/system.h: At global scope:
/usr/src/linux-2.4/include/asm/system.h:240: parse error before `new'
/usr/src/linux-2.4/include/asm/system.h: In function `long unsigned int
__cmpxchg(...)':
/usr/src/linux-2.4/include/asm/system.h:243: `size' undeclared (first use this
function)
/usr/src/linux-2.4/include/asm/system.h:243: (Each undeclared identifier is
reported only once for each function it appears in.)
/usr/src/linux-2.4/include/asm/system.h:247: parse error before `)' token
/usr/src/linux-2.4/include/asm/system.h:253: parse error before `)' token
/usr/src/linux-2.4/include/asm/system.h:259: parse error before `)' token
/usr/src/linux-2.4/include/asm/system.h:263: `old' undeclared (first use this
function)
In file included from /usr/src/linux-2.4/include/linux/capability.h:17,
from /usr/src/linux-2.4/include/linux/binfmts.h:4,
from /usr/src/linux-2.4/include/linux/sched.h:10,
from /usr/src/linux-2.4/include/linux/mm.h:22,
from /usr/src/linux-2.4/include/linux/slab.h:14,
from hello.cpp:15:
/usr/src/linux-2.4/include/linux/fs.h: At global scope:
/usr/src/linux-2.4/include/linux/fs.h:655: parse error before string constant
In file included from /usr/src/linux-2.4/include/linux/sched.h:10,
from /usr/src/linux-2.4/include/linux/mm.h:22,
from /usr/src/linux-2.4/include/linux/slab.h:14,
from hello.cpp:15:
/usr/src/linux-2.4/include/linux/binfmts.h:63: parse error before `new'
In file included from /usr/src/linux-2.4/include/linux/sched.h:28,
from /usr/src/linux-2.4/include/linux/mm.h:22,
from /usr/src/linux-2.4/include/linux/slab.h:14,
from hello.cpp:15:
/usr/src/linux-2.4/include/linux/signal.h: In function `void
sigfillset(sigset_t*)':
/usr/src/linux-2.4/include/linux/signal.h:163: warning: assignment of negative
value `-1' to `long unsigned int'
/usr/src/linux-2.4/include/linux/signal.h:163: warning: argument of negative
value `-1' to `long unsigned int'
/usr/src/linux-2.4/include/linux/signal.h:164: warning: assignment of negative
value `-1' to `long unsigned int'
/usr/src/linux-2.4/include/linux/signal.h:164: warning: argument of negative
value `-1' to `long unsigned int'
/usr/src/linux-2.4/include/linux/signal.h: In function `void
siginitsetinv(sigset_t*, long unsigned int)':
/usr/src/linux-2.4/include/linux/signal.h:207: warning: assignment of negative
value `-1' to `long unsigned int'
/usr/src/linux-2.4/include/linux/signal.h:207: warning: argument of negative
value `-1' to `long unsigned int'
In file included from /usr/src/linux-2.4/include/linux/mm.h:22,
from /usr/src/linux-2.4/include/linux/slab.h:14,
from hello.cpp:15:
/usr/src/linux-2.4/include/linux/sched.h: At global scope:
/usr/src/linux-2.4/include/linux/sched.h:212: parse error before `;' token
/usr/src/linux-2.4/include/linux/sched.h:493: parse error before `*' token
In file included from /usr/src/linux-2.4/include/linux/mm.h:31,
from /usr/src/linux-2.4/include/linux/slab.h:14,
from hello.cpp:15:
/usr/src/linux-2.4/include/linux/swap.h:106: conflicting types for `struct
zone_t'
/usr/src/linux-2.4/include/linux/mmzone.h:116: previous declaration as `typedef
struct zone_struct zone_t'
In file included from /usr/src/linux-2.4/include/linux/slab.h:14,
from hello.cpp:15:
/usr/src/linux-2.4/include/linux/mm.h:205: parse error before `virtual'
/usr/src/linux-2.4/include/linux/mm.h: In function `long unsigned int
do_mmap(file*, long unsigned int, long unsigned int, long unsigned int, long
unsigned int, long unsigned int)':
/usr/src/linux-2.4/include/linux/mm.h:648: warning: initialization of negative
value `-22' to `long unsigned int'
/usr/src/linux-2.4/include/linux/mm.h:648: warning: argument of negative value
`-22' to `long unsigned int'
In file included from hello.cpp:17:
myheap.h: In function `void* _alloc_pool(unsigned int)':
myheap.h:21: `nNumofBytes' undeclared (first use this function)
myheap.h: At global scope:
myheap.h:24: syntax error before `operator'
myheap.h:29: syntax error before `operator'
[root@localhost Hello]#
我在myheap.h中加了new和delete运算符定义
[root@localhost Hello]# g++ -c -I /usr/src/linux-2.4/include/ hello.cpp
In file included from /usr/src/linux-2.4/include/linux/module.h:12,
from hello.cpp:11:
/usr/src/linux-2.4/include/linux/list.h: In function `void
list_del(list_head*)':
/usr/src/linux-2.4/include/linux/list.h:94: invalid conversion from `void*' to
`list_head*'
/usr/src/linux-2.4/include/linux/list.h:95: invalid conversion from `void*' to
`list_head*'
In file included from /usr/src/linux-2.4/include/linux/fs.h:12,
from /usr/src/linux-2.4/include/linux/capability.h:17,
from /usr/src/linux-2.4/include/linux/binfmts.h:4,
from /usr/src/linux-2.4/include/linux/sched.h:10,
from /usr/src/linux-2.4/include/linux/mm.h:22,
from /usr/src/linux-2.4/include/linux/slab.h:14,
from hello.cpp:15:
/usr/src/linux-2.4/include/linux/wait.h: In function `void
init_waitqueue_head(wait_queue_head_t*)':
/usr/src/linux-2.4/include/linux/wait.h:165: parse error before `}' token
/usr/src/linux-2.4/include/linux/wait.h:165: excess elements in aggregate
initializer
In file included from /usr/src/linux-2.4/include/asm/semaphore.h:39,
from /usr/src/linux-2.4/include/linux/fs.h:200,
from /usr/src/linux-2.4/include/linux/capability.h:17,
from /usr/src/linux-2.4/include/linux/binfmts.h:4,
from /usr/src/linux-2.4/include/linux/sched.h:10,
from /usr/src/linux-2.4/include/linux/mm.h:22,
from /usr/src/linux-2.4/include/linux/slab.h:14,
from hello.cpp:15:
/usr/src/linux-2.4/include/asm/system.h: At global scope:
/usr/src/linux-2.4/include/asm/system.h:240: parse error before `new'
/usr/src/linux-2.4/include/asm/system.h: In function `long unsigned int
__cmpxchg(...)':
/usr/src/linux-2.4/include/asm/system.h:243: `size' undeclared (first use this
function)
/usr/src/linux-2.4/include/asm/system.h:243: (Each undeclared identifier is
reported only once for each function it appears in.)
/usr/src/linux-2.4/include/asm/system.h:247: parse error before `)' token
/usr/src/linux-2.4/include/asm/system.h:253: parse error before `)' token
/usr/src/linux-2.4/include/asm/system.h:259: parse error before `)' token
/usr/src/linux-2.4/include/asm/system.h:263: `old' undeclared (first use this
function)
In file included from /usr/src/linux-2.4/include/linux/capability.h:17,
from /usr/src/linux-2.4/include/linux/binfmts.h:4,
from /usr/src/linux-2.4/include/linux/sched.h:10,
from /usr/src/linux-2.4/include/linux/mm.h:22,
from /usr/src/linux-2.4/include/linux/slab.h:14,
from hello.cpp:15:
/usr/src/linux-2.4/include/linux/fs.h: At global scope:
/usr/src/linux-2.4/include/linux/fs.h:655: parse error before string constant
In file included from /usr/src/linux-2.4/include/linux/sched.h:10,
from /usr/src/linux-2.4/include/linux/mm.h:22,
from /usr/src/linux-2.4/include/linux/slab.h:14,
from hello.cpp:15:
/usr/src/linux-2.4/include/linux/binfmts.h:63: parse error before `new'
In file included from /usr/src/linux-2.4/include/linux/sched.h:28,
from /usr/src/linux-2.4/include/linux/mm.h:22,
from /usr/src/linux-2.4/include/linux/slab.h:14,
from hello.cpp:15:
/usr/src/linux-2.4/include/linux/signal.h: In function `void
sigfillset(sigset_t*)':
/usr/src/linux-2.4/include/linux/signal.h:163: warning: assignment of negative
value `-1' to `long unsigned int'
/usr/src/linux-2.4/include/linux/signal.h:163: warning: argument of negative
value `-1' to `long unsigned int'
/usr/src/linux-2.4/include/linux/signal.h:164: warning: assignment of negative
value `-1' to `long unsigned int'
/usr/src/linux-2.4/include/linux/signal.h:164: warning: argument of negative
value `-1' to `long unsigned int'
/usr/src/linux-2.4/include/linux/signal.h: In function `void
siginitsetinv(sigset_t*, long unsigned int)':
/usr/src/linux-2.4/include/linux/signal.h:207: warning: assignment of negative
value `-1' to `long unsigned int'
/usr/src/linux-2.4/include/linux/signal.h:207: warning: argument of negative
value `-1' to `long unsigned int'
In file included from /usr/src/linux-2.4/include/linux/mm.h:22,
from /usr/src/linux-2.4/include/linux/slab.h:14,
from hello.cpp:15:
/usr/src/linux-2.4/include/linux/sched.h: At global scope:
/usr/src/linux-2.4/include/linux/sched.h:212: parse error before `;' token
/usr/src/linux-2.4/include/linux/sched.h:493: parse error before `*' token
In file included from /usr/src/linux-2.4/include/linux/mm.h:31,
from /usr/src/linux-2.4/include/linux/slab.h:14,
from hello.cpp:15:
/usr/src/linux-2.4/include/linux/swap.h:106: conflicting types for `struct
zone_t'
/usr/src/linux-2.4/include/linux/mmzone.h:116: previous declaration as `typedef
struct zone_struct zone_t'
In file included from /usr/src/linux-2.4/include/linux/slab.h:14,
from hello.cpp:15:
/usr/src/linux-2.4/include/linux/mm.h:205: parse error before `virtual'
/usr/src/linux-2.4/include/linux/mm.h: In function `long unsigned int
do_mmap(file*, long unsigned int, long unsigned int, long unsigned int, long
unsigned int, long unsigned int)':
/usr/src/linux-2.4/include/linux/mm.h:648: warning: initialization of negative
value `-22' to `long unsigned int'
/usr/src/linux-2.4/include/linux/mm.h:648: warning: argument of negative value
`-22' to `long unsigned int'
In file included from hello.cpp:17:
myheap.h: In function `void* _alloc_pool(unsigned int)':
myheap.h:21: `nNumofBytes' undeclared (first use this function)
myheap.h: At global scope:
myheap.h:24: syntax error before `operator'
myheap.h:29: syntax error before `operator'
[root@localhost Hello]#
我在myheap.h中加了new和delete运算符定义
|
1 不能用C++写内核驱动
2 内核驱动也不是这样编译的
3 看ldd3
2 内核驱动也不是这样编译的
3 看ldd3
|
把函數用extern "C" 包起來試試看吧。C++的編譯器和C的編譯器差別相當大,這樣玩恐怕你的代碼移植性會很差
而且C++的特定是依賴于很多的庫,這些庫是構建在OS之上的,內核級別的module執行的時候,這些庫還不存在
呢。你所謂的用C++來寫驅動,也只是用C++的那部分面向過程的C feature罷了,并不是真正意義上的C++。個人
覺得你這樣的做法屬於給自己找麻煩,費力不討好,呵呵
|
“因为我习惯...所以我就...”这样的惯性很不好,并且很容易使自己走进死胡同。
现在你碰到的现象就是对上述说法的举例。
|
其实一般编译器或者链接程序都是支持C和C++的,不过驱动不支持C++而已
楼主想在驱动中使用伪C的方法是行不通的
楼主想在驱动中使用伪C的方法是行不通的
|
楼主牛人,建议还是用gcC编译驱动,不要钻牛角
|
up 一下~~~
用C++写啊~~~
真牛~~~
用C++写啊~~~
真牛~~~
|
...
|
其实楼主可以用JAVA或.Net试试写Linux驱动,楼主是牛人,牛人就表示用什么语言无所谓,关键是思想,我相信楼主会成功的,加油!!!!
|
不知道你这是什么驱动.字符块设备驱动吗?居然还有重载...晕死.
你拿设备驱动那本书来看看先
你拿设备驱动那本书来看看先