Gomu Gomu - 2 years ago 177
Linux Question

Gcc compilation : Bitops.h error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’

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


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)

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


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.

Answer Source
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download