0
votes

I'm trying to build a file using gcc. It includes mutex.h.

Makefile:

CC = gcc
CFLAGS = -I/usr/src/linux-headers-3.13.0-32/include 
CFLAGS += -I/usr/src/linux-headers-3.13.0-32/arch/x86/include

SOURCES := $(wildcard *.c)

all: $(SOURCES)
        $(CC) $(CFLAGS) $(SOURCES) 

When I give make, I'm getting the following errors.

Error:

gcc -I/usr/src/linux-headers-3.13.0-32/include -I/usr/src/linux-headers-3.13.0-32/arch/x86/include  app.c rtos.c
In file included from /usr/src/linux-headers-3.13.0-32/include/linux/bitops.h:33:0,
                 from /usr/src/linux-headers-3.13.0-32/include/linux/kernel.h:10,
                 from /usr/src/linux-headers-3.13.0-32/arch/x86/include/asm/percpu.h:44,
                 from /usr/src/linux-headers-3.13.0-32/arch/x86/include/asm/current.h:5,
                 from /usr/src/linux-headers-3.13.0-32/include/linux/mutex.h:13,
                 from rtos.c:55:
  /usr/src/linux-headers-3.13.0-32/arch/x86/include/asm/bitops.h:70:24: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
    /usr/src/linux-headers-3.13.0-32/arch/x86/include/asm/bitops.h:108:24: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
    /usr/src/linux-headers-3.13.0-32/arch/x86/include/asm/bitops.h:218:24: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’
    /usr/src/linux-headers-3.13.0-32/arch/x86/include/asm/bitops.h:310:24: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘int’

The line 218 in /usr/src/linux-headers-3.13.0-32/arch/x86/include/asm/bitops.h, that shows error is the first line of the below code snippet.

static __always_inline int
test_and_set_bit_lock(long nr, volatile unsigned long *addr)
{
        return test_and_set_bit(nr, addr);
}

I don't find anything incorrect with this type of function definition.

Please give me some pointers if I'm missing something in my Makefile.

1
Can you show us your file at the area that includes bitops.h?Joe
@Joe I haven't included bitops.h directly. I have included only <linux/mutex.h>. Internally one of the header files in it, includes this file. I have updated the error output.Gomu

1 Answers

2
votes
CFLAGS = -I/usr/src/linux-headers-3.13.0-32/include 
CFLAGS += -I/usr/src/linux-headers-3.13.0-32/arch/x86/include

Don't do that.

Those headers are for use in the Linux kernel, and in kernel modules. They are not intended for use in userspace applications.

Depending on what atomic operations you need, you may be able to use GCC's atomic builtins as a more compatible alternative.