2

I try to compile my code with c11 mode. Here is my make file:

obj-m := message_slot.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
CFLAGS=-g -std=c11 -Wall -pedantic

all:
    $(MAKE) -C $(KDIR) M=$(PWD) modules


clean:
    $(MAKE) -C $(KDIR) M=$(PWD) clean

for some reason during compilation, the compiler still try to compile the code with c90. Does anyone understand why?

/home/eran/CLionProjects/tau_os_ex3/message_slot.c:29:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
Jens Gustedt
  • 76,821
  • 6
  • 102
  • 177
Mr P
  • 113
  • 8
  • `c++11` chooses the C++ 11 standard. If you want to use the C 11 standard, choose `c11`. And, as John says, use the `CFLAGS` variable (for C compilers) not the `CXXFLAGS` variable (for C++ compilers) – MadScientist Dec 15 '20 at 01:24
  • This has nothing to do with C11 itself, but with your build system and your configuration of make. This depends on a lot of things, your OS, your compiler, ... You should also provide more information, e.g the compilation line that your make has really chosen to execute. – Jens Gustedt Dec 15 '20 at 15:44

1 Answers1

1

CXXFLAGS conveys build flags for C++, but the error message indicates that you are trying to build a C source. C compiler flags go in CFLAGS.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157