2016-12-23 145 views
-2

我在文件platform.h的結構定義:typedef結構指針

typedef struct { 
    VL53L0X_DevData_t Data; 
    uint8_t I2cDevAddr; 
    uint8_t comms_type; 
    uint16_t comms_speed_khz; 
    uint16_t devID; 
    I2C_HandleTypeDef * i2c_handle; 
} VL53L0X_Dev_t; 

而且在同一個文件的類型定義的指針這樣的:

typedef VL53L0X_Dev_t* VL53L0X_DEV; 

在另一個文件中,參考到VL53L0X_DEV失敗error: unknown type name 'VL53L0X_DEV' 我在其他文件中包含platform.h。這有什麼問題?

EDIT

我卡使用由供應商提供的,因此沒有多大範圍是否與指針的typedef廢除或用於提供MCVE示例這個代碼(它的很多) 。這是相關的構建日誌。它似乎包括vl53l0x_platform.h文件好吧。謝謝你的幫助!

1> >>Building build/vl53l0x_platform.o 
1> arm-none-eabi-gcc -ffreestanding -mcpu=cortex-m4 -mthumb -mfloat-abi=soft -Og -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-move-loop-invariants -g3 -nostartfiles -I"conf" -I"inc" -IC:/Users/sohail/Documents/Cloud/STM32Cube_FW_F4_V1.7.0/Drivers/STM32F4xx_HAL_Driver/Inc -IC:/Users/sohail/Documents/Cloud/STM32Cube_FW_F4_V1.7.0/Drivers/CMSIS/Include -I"C:\Users\sohail\Documents\gcc-arm_launchpad_binaries\lib\gcc\arm-none-eabi\4.9.3\include" -I"C:\Users\sohail\Documents\gcc-arm_launchpad_binaries\arm-none-eabi\include\sys" -I"C:\Users\sohail\Documents\gcc-arm_launchpad_binaries\arm-none-eabi\include" -std=gnu11 -c -o build/vl53l0x_platform.o src/vl53l0x_platform.c 
1> In file included from inc/vl53l0x_api.h:33:0, 
1>     from inc/main.h:44, 
1>     from inc/vl53l0x_platform.h:34, 
1>     from src/vl53l0x_platform.c:37: 
1> inc/vl53l0x_api_strings.h:39:39: error: unknown type name 'VL53L0X_DEV' 
1> VL53L0X_Error VL53L0X_get_device_info(VL53L0X_DEV Dev, VL53L0X_DeviceInfo_t *pVL53L0X_DeviceInfo); 
1>          ^
+0

檢查預處理的代碼。 –

+4

您應該發佈[MCVE](http://stackoverflow.com/help/mcve) – LPs

+3

完全猜測:「paltform.h」之前包含的某些include需要「VL53L0X_DEV」類型?如果是'platform.h'必須位於其他頭文件的頂部。 – LPs

回答

1

從評論:

你可能對你的頭一個循環依賴。

一些包括在platform.h之前的要求包括VL53L0X_DEV類型?如果是platform.h必須位於其他標題包含的頂部。

如果vl53l0x_api.h包含在platform.h中,那麼您必須在include之前定義struct。