[英]c: unknown type name
I have the following code (in main.c) to initialise a typedef
struct that is in a header file (phOsal.h). 我有以下代码(位于main.c中)初始化头文件(phOsal.h)中的
typedef
结构。
main.c main.c
#include <phOsal.h>
...
phOsal_RPi_DataParams_t osal;
...
phOsal.h 语音
/**
* \brief RPi osal parameter stucture
*/
typedef struct
{
uint16_t wId; /**< ID of this component, do not modify */
/* Other stuff */
uint8_t * bLEDPins;
uint8_t bLEDCount;
uint8_t * bDIPSWPins;
uint8_t bDIPSWCount;
uint8_t bCommDev_ResetPin;
} phOsal_RPi_DataParams_t;
when I compile this using the cmake commands cmake ./Source
and make
I get a compile error. 当我使用cmake命令
cmake ./Source
make
编译时,出现编译错误。
error: unknown type name 'phOsal_RPi_DataParams_t'
If I comment it out the program compiles fine. 如果我将其注释掉,程序可以正常编译。 Also in
main.c
there are other DataParams
that are declared and used but do not throw the compiler error. 同样在
main.c
还有其他DataParams
被声明和使用,但不会引发编译器错误。
I have read a number of questions on here and none of them seem to be what is wrong and have tried the following. 我在这里阅读了许多问题,但似乎都没有错,并尝试了以下方法。
#ifndef
and #define
are correct #ifndef
和#define
是否正确 struct dataparams {...};
struct dataparams {...};
and then called it in main.c
using struct dataparams osal;
struct dataparams osal;
在main.c
调用它struct dataparams osal;
Any help would be much appreciated. 任何帮助将非常感激。
An option would be to declare your struct as: 一种选择是将您的结构声明为:
typedef struct phOsal_RPi_DataParams_t { ... }phOsal_RPi_DataParams_t;
Look here when your aliasing a struct with typedef at the declaration example: 在声明示例中使用typedef为结构别名时,请看这里:
http://en.wikipedia.org/wiki/Struct_(C_programming_language)#typedef http://zh.wikipedia.org/wiki/Struct_(C_programming_language)#typedef
if you want to you the "dataparams" alias then do the following: 如果要使用“ dataparams”别名,请执行以下操作:
typedef struct phOsal_RPi_DataParams_t
{
...
} dataparams;
Then in main.c ditch the struct and just declar it as: 然后在main.c中抛弃该结构并将其声明为:
dataparams osal;
The ordering of where you declare it and your main may be wrong as the commenters suggested, and yes the include should be in "" keep that. 正如注释者所建议的那样,声明它和主体的位置的顺序可能是错误的,是的,应该在“”中包含该内容。 Here's a good model to follow:
以下是一个很好的模型:
Unknown type name with typedef struct in C C中具有typedef结构的未知类型名称
Edited because of comments. 由于评论而被编辑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.