交叉编译配置命令如下:
PKG_CONFIG_PATH="$SYSROOT/usr/lib/pkgconfig" ../configure --prefix=/home/dubu/installtest --target-list=aarch64-softmmu --cpu=aarch64 --cross-prefix=aarch64-linux-android33- --cc=aarch64-linux-android33-clang --cxx=aarch64-linux-android33-clang++ --host-cc=aarch64-linux-android33-gcc
make的时候报的错误,configure的时候没有问题
1.报错内容如下
[66/2776] Compiling C object subprojects/libvhost-user/libvhost-user.a.p/libvhost-user.c.o
FAILED: subprojects/libvhost-user/libvhost-user.a.p/libvhost-user.c.o
aarch64-linux-android33-clang -Isubprojects/libvhost-user/libvhost-user.a.p -Isubprojects/libvhost-user -I../subprojects/libvhost-user -fcolor-diagnostics -Wall -Winvalid-pch -std=gnu99 -O2 -g -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -Wold-style-definition -Wtype-limits -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-body -Wnested-externs -Wendif-labels -Wexpansion-to-defined -Wno-initializer-overrides -Wno-missing-include-dirs -Wno-shift-negative-value -Wno-string-plus-int -Wno-typedef-redefinition -Wno-tautological-type-limit-compare -Wno-psabi -fstack-protector-strong -fPIE -pthread -D_GNU_SOURCE -MD -MQ subprojects/libvhost-user/libvhost-user.a.p/libvhost-user.c.o -MF subprojects/libvhost-user/libvhost-user.a.p/libvhost-user.c.o.d -o subprojects/libvhost-user/libvhost-user.a.p/libvhost-user.c.o -c ../subprojects/libvhost-user/libvhost-user.c
In file included from ../subprojects/libvhost-user/libvhost-user.c:45:
In file included from ../subprojects/libvhost-user/libvhost-user.h:23:
In file included from ../subprojects/libvhost-user/standard-headers/linux/virtio_ring.h:36:
../subprojects/libvhost-user/standard-headers/linux/virtio_types.h:44:19: error: typedef redefinition with different types ('uint64_t' (aka 'unsigned long') vs '__u64' (aka 'unsigned long long'))
typedef uint64_t __virtio64;
^
/home/dubu/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/linux/virtio_types.h:24:25: note: previous definition is here
typedef __u64 __bitwise __virtio64;
^
In file included from ../subprojects/libvhost-user/libvhost-user.c:45:
In file included from ../subprojects/libvhost-user/libvhost-user.h:23:
../subprojects/libvhost-user/standard-headers/linux/virtio_ring.h:95:8: error: redefinition of 'vring_desc'
struct vring_desc {
^
/home/dubu/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/linux/virtio_ring.h:40:8: note: previous definition is here
struct vring_desc {
^
In file included from ../subprojects/libvhost-user/libvhost-user.c:45:
In file included from ../subprojects/libvhost-user/libvhost-user.h:23:
../subprojects/libvhost-user/standard-headers/linux/virtio_ring.h:106:8: error: redefinition of 'vring_avail'
struct vring_avail {
^
/home/dubu/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/linux/virtio_ring.h:46:8: note: previous definition is here
struct vring_avail {
^
In file included from ../subprojects/libvhost-user/libvhost-user.c:45:
In file included from ../subprojects/libvhost-user/libvhost-user.h:23:
../subprojects/libvhost-user/standard-headers/linux/virtio_ring.h:113:8: error: redefinition of 'vring_used_elem'
struct vring_used_elem {
^
/home/dubu/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/linux/virtio_ring.h:51:8: note: previous definition is here
struct vring_used_elem {
^
In file included from ../subprojects/libvhost-user/libvhost-user.c:45:
In file included from ../subprojects/libvhost-user/libvhost-user.h:23:
../subprojects/libvhost-user/standard-headers/linux/virtio_ring.h:123:8: error: redefinition of 'vring_used'
struct vring_used {
^
/home/dubu/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/linux/virtio_ring.h:56:8: note: previous definition is here
struct vring_used {
^
In file included from ../subprojects/libvhost-user/libvhost-user.c:45:
In file included from ../subprojects/libvhost-user/libvhost-user.h:23:
../subprojects/libvhost-user/standard-headers/linux/virtio_ring.h:150:8: error: redefinition of 'vring'
struct vring {
^
/home/dubu/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/linux/virtio_ring.h:64:8: note: previous definition is here
struct vring {
^
In file included from ../subprojects/libvhost-user/libvhost-user.c:45:
In file included from ../subprojects/libvhost-user/libvhost-user.h:23:
../subprojects/libvhost-user/standard-headers/linux/virtio_ring.h:189:9: warning: 'vring_avail_event' macro redefined [-Wmacro-redefined]
#define vring_avail_event(vr) (*(__virtio16 *)&(vr)->used->ring[(vr)->num])
^
/home/dubu/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/linux/virtio_ring.h:72:9: note: previous definition is here
#define vring_avail_event(vr) (* (__virtio16 *) & (vr)->used->ring[(vr)->num])
^
In file included from ../subprojects/libvhost-user/libvhost-user.c:45:
In file included from ../subprojects/libvhost-user/libvhost-user.h:23:
../subprojects/libvhost-user/standard-headers/linux/virtio_ring.h:191:20: error: redefinition of 'vring_init'
static inline void vring_init(struct vring *vr, unsigned int num, void *p,
^
/home/dubu/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/linux/virtio_ring.h:74:24: note: previous definition is here
static __inline__ void vring_init(struct vring *vr, unsigned int num, void *p,
^
In file included from ../subprojects/libvhost-user/libvhost-user.c:45:
In file included from ../subprojects/libvhost-user/libvhost-user.h:23:
../subprojects/libvhost-user/standard-headers/linux/virtio_ring.h:201:24: error: redefinition of 'vring_size'
static inline unsigned vring_size(unsigned int num, unsigned long align)
^
/home/dubu/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/linux/virtio_ring.h:84:28: note: previous definition is here
static __inline__ unsigned vring_size(unsigned int num, unsigned long align)
^
In file included from ../subprojects/libvhost-user/libvhost-user.c:45:
In file included from ../subprojects/libvhost-user/libvhost-user.h:23:
../subprojects/libvhost-user/standard-headers/linux/virtio_ring.h:214:19: error: redefinition of 'vring_need_event'
static inline int vring_need_event(uint16_t event_idx, uint16_t new_idx, uint16_t old)
^
/home/dubu/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/linux/virtio_ring.h:95:23: note: previous definition is here
static __inline__ int vring_need_event(__u16 event_idx, __u16 new_idx, __u16 old)
^
In file included from ../subprojects/libvhost-user/libvhost-user.c:45:
In file included from ../subprojects/libvhost-user/libvhost-user.h:23:
../subprojects/libvhost-user/standard-headers/linux/virtio_ring.h:224:8: error: redefinition of 'vring_packed_desc_event'
struct vring_packed_desc_event {
^
/home/dubu/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/linux/virtio_ring.h:105:8: note: previous definition is here
struct vring_packed_desc_event {
^
In file included from ../subprojects/libvhost-user/libvhost-user.c:45:
In file included from ../subprojects/libvhost-user/libvhost-user.h:23:
../subprojects/libvhost-user/standard-headers/linux/virtio_ring.h:231:8: error: redefinition of 'vring_packed_desc'
struct vring_packed_desc {
^
/home/dubu/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/linux/virtio_ring.h:109:8: note: previous definition is here
struct vring_packed_desc {
^
1 warning and 11 errors generated.
ninja: build stopped: subcommand failed.
make: *** [Makefile:163:run-ninja] 错误 1
上面出现了那么多的重定义,那么为什么正常编译(就是在本地电脑编译,不是交叉编译)的时候就没有出现这么多重定义。其实正常编译的时候用的头文件都是/usr/include/linux该目录下的头文件,该目录下的头文件与qemu目录下的头文件的宏定义是一模一样,所以包了/usr/include/linux该目录下的头文件以后就不会再包含qemu目录下的头文件。而我们交叉编译的时候用的是$SYSROOT/usr/include/linux下的头文件,该目录下头文件的宏定义与qemu目录下的头文件的宏定义不一样所以会出现重复定义的情况。所以我们需要修改qemu目录下的头文件的宏定义。
以virtio_ring.h为例子:
/usr/include/linux/virtio_ring.h的宏定义为:
#ifndef _LINUX_VIRTIO_RING_H
#define _LINUX_VIRTIO_RING_H
qemu目录下的头文件virtio_ring.h的宏定义 为:
#ifndef _LINUX_VIRTIO_RING_H
#define _LINUX_VIRTIO_RING_H
$SYSROOT/usr/include/linux下的头文件 virtio_ring.h宏定义 为:
#ifndef _UAPI_LINUX_VIRTIO_RING_H
#define _UAPI_LINUX_VIRTIO_RING_H
所以把出现redifine报错的的文件的宏修改以下就可以了。
这里要把qemu目录下的头文件virtio_ring.h的宏定义修改为_UAPI_LINUX_VIRTIO_RING_H。
如果把$SYSROOT/usr/include/linux(即NDK-r25)下的头文件 virtio_ring.h宏定义修改为_LINUX_VIRTIO_RING_H问题还是存在的。这个我不知道为什么?有大神的话清赐教。