最近尝试了在 Ubuntu 18.04 上编译安装 qemu-4.2,qemu-5.0.0,发现编译遇到了问题。
问题如下:
/usr/include/linux/swab.h: In function ‘__swab’:
CC hw/char/digic-uart.o
CC hw/char/omap_uart.o
CC hw/char/exynos4210_uart.o
xxx/qemu-5.0.0/include/qemu/bitops.h:20:34: warning: "sizeof" is not defined, evaluates to 0 [-Wundef]
#define BITS_PER_LONG (sizeof (unsigned long) * BITS_PER_BYTE)
^
xxx/qemu-5.0.0/include/qemu/bitops.h:20:41: error: missing binary operator before token "("
#define BITS_PER_LONG (sizeof (unsigned long) * BITS_PER_BYTE)
...
xxx/qemu-5.0.0/rules.mak:69: recipe for target 'block/file-posix.o' failed
make: *** [block/file-posix.o] Error 1
make: *** Waiting for unfinished jobs....
经过分析是因为预编译器不认识 sizeof
运算符1。
因此应当避免使用 sizeof
。解决办法,修改 qemu-5.0.0/include/qemu/bitops.h
。
#define BITS_PER_LONG (sizeof (unsigned long) * BITS_PER_BYTE)
改成
#define BITS_PER_LONG (__SIZEOF_LONG__ * BITS_PER_BYTE)
https://stackoverflow.com/questions/21338385/what-does-the-compiler-error-missing-binary-operator-before-token-mean ↩︎