我正在尝试使用gcc构建文件。它包括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)
$(CC) $(CFLAGS) $(SOURCES)
当我付费时,我收到以下错误。
错误:
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’
/usr/src/linux-headers-3.13.0-32/arch/x86/include/asm/bitops.h中的第218行,显示错误是以下代码段的第一行。
static __always_inline int
test_and_set_bit_lock(long nr, volatile unsigned long *addr)
{
return test_and_set_bit(nr, addr);
}
我发现这种功能定义不正确。
如果我在Makefile中遗漏了某些内容,请给我一些指示。
答案 0 :(得分:2)
CFLAGS = -I/usr/src/linux-headers-3.13.0-32/include
CFLAGS += -I/usr/src/linux-headers-3.13.0-32/arch/x86/include
不要那样做。
这些标头用于Linux内核和内核模块。它们不适用于用户空间应用程序。
根据您需要的原子操作,您可以使用GCC's atomic builtins作为更兼容的替代方案。