【问题标题】:Gcc compilation : Bitops.h error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’Gcc 编译:Bitops.h 错误:预期的“=”、“,”、“;”、“asm”或“__attribute__”
【发布时间】:2017-05-23 06:36:25
【问题描述】:

我正在尝试使用 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) 

当我进行 make 时,出现以下错误。

错误:

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行,显示错误的是下面代码sn-p的第一行。

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

我没有发现这种类型的函数定义有任何不正确之处。

如果我的 Makefile 中缺少某些内容,请给我一些指示。

【问题讨论】:

  • 您能否向我们展示您在包含 bitops.h 的区域中的文件?
  • @Joe 我没有直接包含 bitops.h。我只包含了 。其中一个头文件在内部包含此文件。我已经更新了错误输出。

标签: linux gcc makefile compiler-errors


【解决方案1】:
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 作为更兼容的替代方案。

【讨论】:

  • 好的,谢谢。我将删除那些包含,而是将 pthread.h 用于互斥锁。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多