Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile a Linux kernel module using -std=gnu99?

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

I assume this is because the main Linux kernel Makefile is set to compile using a non-C99 standard. I searched around I found this answer here on stackoverflow: How to use make and compile as C99?

So I naturally tried the following in my Makefile:

ccflags-y := -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.

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

EDIT:

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?

like image 582
Vilhelm Gray Avatar asked Apr 09 '13 18:04

Vilhelm Gray


1 Answers

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.

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.

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

For example:

ccflags-y := -std=gnu99 -Wno-declaration-after-statement
like image 130
Vilhelm Gray Avatar answered Sep 21 '22 12:09

Vilhelm Gray