error: braces around scalar initializer for type 'void*'编译错误解析
来源:互联网 发布:网络数据储存在哪里 编辑:程序博客网 时间:2024/06/05 18:07
这里分享一下题主遇到的一个编译错误及解决过程,供大家参考。
一、编译错误
编译错误的log如下:
XXXXXXXX@shanN07:~/pikel/SC9820W/vendor/sprd/open-source/libs/libsensors_sprd$ mm -B
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=4.4.4
TARGET_PRODUCT=sp9820a_3c10_native
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
TARGET_CPU_VARIANT=cortex-a7
HOST_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-3.19.0-25-generic-x86_64-with-Ubuntu-14.04-trusty
HOST_BUILD_TYPE=release
BUILD_ID=KTU84P
OUT_DIR=out
============================================
No private recovery resources for TARGET_DEVICE sp9820a_3c10
basename: missing operand
Try 'basename --help' for more information.
make: Entering directory `/home5/XXXXXXXX/pikel/SC9820W'
make: Warning: File `out/target/product/sp9820a_3c10/obj/SHARED_LIBRARIES/sensors.sc8830_intermediates/sensors.P' has modification time 23 s in the future
Import includes file: out/target/product/sp9820a_3c10/obj/SHARED_LIBRARIES/sensors.sc8830_intermediates/import_includes
target thumb C++: sensors.sc8830 <= vendor/sprd/open-source/libs/libsensors_sprd/SensorBase.cpp
vendor/sprd/open-source/libs/libsensors_sprd/SensorBase.cpp:100:5: warning: unused parameter 'handle' [-Wunused-parameter]
vendor/sprd/open-source/libs/libsensors_sprd/SensorBase.cpp:100:5: warning: unused parameter 'ns' [-Wunused-parameter]
vendor/sprd/open-source/libs/libsensors_sprd/SensorBase.cpp:105:9: warning: unused parameter 'handle' [-Wunused-parameter]
vendor/sprd/open-source/libs/libsensors_sprd/SensorBase.cpp:110:5: warning: unused parameter 'list' [-Wunused-parameter]
vendor/sprd/open-source/libs/libsensors_sprd/SensorBase.cpp:115:6: warning: unused parameter 'buf' [-Wunused-parameter]
target thumb C++: sensors.sc8830 <= vendor/sprd/open-source/libs/libsensors_sprd/SensorCoordinate.cpp
target thumb C++: sensors.sc8830 <= vendor/sprd/open-source/libs/libsensors_sprd/InputEventReader.cpp
target thumb C++: sensors.sc8830 <= vendor/sprd/open-source/libs/libsensors_sprd/sensors.cpp
vendor/sprd/open-source/libs/libsensors_sprd/sensors.cpp:70:12: warning: unused parameter 'module' [-Wunused-parameter]
vendor/sprd/open-source/libs/libsensors_sprd/sensors.cpp:405:12: warning: unused parameter 'id' [-Wunused-parameter]
In file included from vendor/sprd/open-source/libs/libsensors_sprd/sensors.cpp:36:0:
vendor/sprd/open-source/libs/libsensors_sprd/PlsSensor.h:40:20: warning: 'PlsChipInfoList' defined but not used [-Wunused-variable]
vendor/sprd/open-source/libs/libsensors_sprd/PlsSensor.h:50:13: warning: 'PlsNewSuccess' defined but not used [-Wunused-variable]
vendor/sprd/open-source/libs/libsensors_sprd/sensors.cpp:65:13: warning: 'GetChipInfo' defined but not used [-Wunused-variable]
target thumb C++: sensors.sc8830 <= vendor/sprd/open-source/libs/libsensors_sprd/Acc_Lis3dh.cpp
vendor/sprd/open-source/libs/libsensors_sprd/Acc_Lis3dh.cpp:79:1: warning: missing braces around initializer for 'void* [6]' [-Wmissing-braces]
vendor/sprd/open-source/libs/libsensors_sprd/Acc_Lis3dh.cpp:79:1: error: braces around scalar initializer for type 'void*'
make: *** [out/target/product/sp9820a_3c10/obj/SHARED_LIBRARIES/sensors.sc8830_intermediates/Acc_Lis3dh.o] Error 1
make: Leaving directory `/home5/XXXXXXXX/pikel/SC9820W'
二、分析过程
出现编译错误的Acc_Lis3dh.cpp +79行代码如下:
58
59 /*****************************************************************************/
60 static struct sensor_t sSensorList[] = {
61 {
62 "ST LIS3DH 3-axis Accelerometer",
63 "ST",
64 1,
65 SENSORS_ACCELERATION_HANDLE,
66 SENSOR_TYPE_ACCELEROMETER,
67 (GRAVITY_EARTH * 2.0f),
68 (GRAVITY_EARTH) / 1024.0f,
69 0.145f,
70 5000, // fastest is 200Hz
71 0,
72 0,
73 SENSOR_STRING_TYPE_ACCELEROMETER,
74 "",
75 1000000,
76 SENSOR_FLAG_CONTINUOUS_MODE,
77 {},
78 },
79 };
80
题主所用的Acc_Lis3dh.cpp代码在android8.0上编译是没有问题的,
而在android4.4上编译却出现问题,故怀疑是android版本不同导致。
查看android4.4中的sensor_t定义如下:
hardware/libhardware/include/hardware/sensors.h +905行
struct sensor_t {
const char* name;
const char* vendor;
int version;
int handle;
int type;
float maxRange;
float resolution;
float power;
int32_t minDelay;
uint32_t fifoReservedEventCount;
uint32_t fifoMaxEventCount;
/* reserved fields, must be zero */
void* reserved[6];
};
查看android8.0中的sensor_t定义如下:
hardware/libhardware/include/hardware/sensors.h +419行
struct sensor_t {
const char* name;
const char* vendor;
int version;
int handle;
int type;
float maxRange;
float resolution;
float power;
int32_t minDelay;
uint32_t fifoReservedEventCount;
uint32_t fifoMaxEventCount;
const char* stringType;
const char* requiredPermission;
#ifdef __LP64__
int64_t maxDelay;
#else
int32_t maxDelay;
#endif
#ifdef __LP64__
uint64_t flags;
#else
uint32_t flags;
#endif
/* reserved fields, must be zero */
void* reserved[2];
};
对比android4.4与android8.0中的sensor_t定义可知,
73 SENSOR_STRING_TYPE_ACCELEROMETER,
74 "",
75 1000000,
76 SENSOR_FLAG_CONTINUOUS_MODE,
在android4.4中对应为void* reserved[6];域,且注释提示:/* reserved fields, must be zero */。
对void* reserved[6];域赋值引起error: braces around scalar initializer for type 'void*'编译错误。
三、解决方法
将73-76行注释掉后,在android4.4中编译,编译不再报错,如下:
58
59 /*****************************************************************************/
60 static struct sensor_t sSensorList[] = {
61 {
62 "ST LIS3DH 3-axis Accelerometer",
63 "ST",
64 1,
65 SENSORS_ACCELERATION_HANDLE,
66 SENSOR_TYPE_ACCELEROMETER,
67 (GRAVITY_EARTH * 2.0f),
68 (GRAVITY_EARTH) / 1024.0f,
69 0.145f,
70 5000, // fastest is 200Hz
71 0,
72 0,
73 //SENSOR_STRING_TYPE_ACCELEROMETER,
74 //"",
75 //1000000,
76 //SENSOR_FLAG_CONTINUOUS_MODE,
77 {},
78 },
79 };
80
- error: braces around scalar initializer for type 'void*'编译错误解析
- 【原创】arm-linux-gcc “missing braces around initializer”编译错误处理
- warning: missing braces around initializer
- warning: missing braces around initializer
- warning: missing braces around initializer
- [DEBUG]warning: missing braces around initializer
- C语言告警warning: missing braces around initializer详解
- ADS编译错误 error:type disagreement for
- error: variable '__this_module' has initializer but incomplete type错误解决
- error: variable '__this_module' has initializer but incomplete type错误解决
- 编译报错void is an invalid type for the variable……错误解决
- NUnit Error: The Type Initializer for … Threw an Exception (And app.config)
- 关于错误: error: variable ‘QApplication app’ has initializer but incomplete type
- 编译错误syntax error : missing ';' before 'type'
- 编译错误syntax error : missing ';' before 'type'
- 编译错误syntax error : missing ';' before 'type'
- 编译错误syntax error : missing ';' before 'type'
- excess elements in scalar initializer
- 167. Two Sum II
- tensorflow 变量简单存储与恢复
- Android 中的网络判断
- 一个初学者对于MVC架构的理解
- java.lang.UnsatisfiedLinkError: no resin_os in java.library.path
- error: braces around scalar initializer for type 'void*'编译错误解析
- 最全Eclipse中项目上有小红叉,但就是找不到报错文件(总结,持续更新)
- hdu 3466 Proud Merchants (01背包 + 结构体的sort排序)
- JavaScript单线程模型
- 基于Restful形式访问远程服务并封装对象
- 随机数生成算法
- angular-bootstrap-nav-tree 插件的应用 abntree
- 欢迎使用CSDN-markdown编辑器
- 树状数组求不带修改前缀最值问题 51NOD 1272 最大距离