如何编译使用-std = gnu99一个Linux内核模块? [英] How to compile a Linux kernel module using -std=gnu99?

查看:2640
本文介绍了如何编译使用-std = gnu99一个Linux内核模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近学会了如何编程简​​单的字符驱动程序和同时与code我注意到,我得到了很多抛出我的C99 code以下GCC警告玩耍:

I've recently learned how to program simple character drivers and while playing around with the code I noticed that I get a lot of the following GCC warnings thrown for my C99 code:

warning: ISO C90 forbids mixed declarations and code

我想这是因为主要的Linux内核Makefile文件设置为使用非C99标准进行编译。我搜索周围,我发现这个答案在这里计算器:<一href=\"http://stackoverflow.com/questions/2935047/how-to-use-make-and-compile-as-c99/5543589#5543589\">How使用化妆和编译为C99?

于是,我试着自然在我的Makefile如下:

So I naturally tried the following in my Makefile:

ccflags-y := -std=gnu99

不幸的是这并不能平息海湾合作委员会的警告。我检查的详细输出使并验证GCC确实用在了 -std = gnu99 上涨了执行结束;所以我有点糊涂了。

Unfortunately this didn't silence the GCC warnings. I checked the verbose output of make and verified that GCC is indeed executed with the -std=gnu99 tacked on at the end; so I'm a bit confused.

如何正确使用 -std = gnu99 选项编译Linux内核模块?

How do I properly compile a Linux kernel module using the -std=gnu99 option?

修改

我注意到GCC输出显示此选项: -Wdeclaration-后声明。这是为什么我收到的警告甚至与 -std = gnu99 选项?

I noticed the GCC output shows this option: -Wdeclaration-after-statement. Is this why I am getting the warnings even with the -std=gnu99 option?

推荐答案

原来, -std = gnu99 确实能使工作的;我开始卸下编译器标志后看到关于C99的功能错误。因此,这意味着别的东西是导致警告打印出除了 -std = 选项。

It turns out that -std=gnu99 does in fact work; I began seeing errors regarding C99 features after removing the compiler flag. So that meant something else was causing the warnings to print out besides the -std= option.

通过通过详细的输出解析后做出V = 1 ,我发现了 -Wdeclaration-后声明选项​​作为海湾合作委员会执行的一部分。这是我看见的ISO C90混合声明警告的原因。

After parsing through the verbose output via make V=1, I discovered the -Wdeclaration-after-statement option as part of the GCC execution. This was the cause of the ISO C90 mixed declaration warnings I saw.

要禁用ISO C90警告,它传递给GCC: -Wno声明-后声明

To disable the ISO C90 warnings, pass this to GCC: -Wno-declaration-after-statement.

例如:

ccflags-y := -std=gnu99 -Wno-declaration-after-statement

这篇关于如何编译使用-std = gnu99一个Linux内核模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆