Reputation: 3529
Hello how to rewrite probably bad construction?
I tryed to ask how to fix it to make it work there,but maybe it's all the bad conception.
Any other solution to do that?
It's compiled in Eclipse using GCC for linux, compiled as C code.
file first.h
#ifndef FIRST_H_
#define FIRST_H_
typedef struct foo
{
int a;
char *c;
} foo_struct;
#endif /* FIRST_H_ */
file second.h:
#ifndef SECOND_H_
#define SECOND_H_
#include "first.h"
typedef struct wtf
{
foo_struct *poleFOO[5];
}wtf_struct;
#endif /* SECOND_H_ */
Concretely in file second.h row foo_struct *poleFOO[5]; throws: "foo_struct could not be resolved" I work on Linux Ubuntu 11.10 using gcc in editor Eclipse for C and C++.
Upvotes: 0
Views: 2595
Reputation: 1
I landed here because I had a similar problem and Eclipse was also to blame (I reproduced using only GCC and it works). I tried to reproduce the OP's issue, but it compiled OK in my environment :/. So I will show what worked for me instead.
The only thing that helped was to make the extern
declaration using struct
, and the actual definition in the source file using the new type I defined with typedef
, like so:
lib1.h:
typedef struct sMyStruct
{
// struct fill
}tMyStruct;
lib2.h:
extern struct sMyStruct my_struct, *p_my_struct;
//extern tMyStruct my_struct, *p_my_struct; // This wouldn't work
lib2.c:
tMyStruct my_struct, *p_my_struct;
With extern tMyStruct
in lib2.h it would not compile (the typedef
was not recognized), no matter what. Cleaning the project wouldn't help, neither would rebuilding the index, etc.
Astonishingly, I tried to reproduce the problem minimally in a new project... and it compiles fine! With both versions! So, I don't know, Eclipse got hung up on some wicked ghost file or something.
I was stuck for days, the only thing that worked on the actual project was what I showed above.
Upvotes: 0
Reputation: 11
I had the same Error: "vuint16 - could not be resolved" for a wrapped type within typedef (mentioned below) and it was successfully resolved by rebuilding the Index in Eclipse Environment(right click on project -> Index -> Rebuild) Note: It is not a compiler error!
[headerfile1: can.h]
#define vuint8 uint8
[headerfile2: can_local.h]
#include "Can.h" /* include all needed types */
typedef struct sCanRxFullInfoStruct
{
vuint16 objectNumber; //error line
} tCanRxFullInfoStruct;
Upvotes: 1
Reputation: 1
I had the same problem after creating a set of typedefs that wrap other types. The solution was to rebuild Eclipse Index - right click on project -> Index -> Rebuild
Upvotes: 0
Reputation: 436
Okay, this is not an error from the compiler but from Eclipse. Simply Googl'ing the error "could not be resolved" points me to articles talking about Eclipse CDT (the eclipse subsystem for C/C++ development).
So it has something to do with Eclipse, your C headers look syntactically right. I believe that without a C file but only headers, Eclipse does not know how to parse the headers only to create its own index database (must be used for intellisense, symbols list, etc.)
I suggest you insert a simple C file including second.h
, and with a main()
function so that the link step passes as well, for example:
#include "second.h"
int main() {
wtf_struct my_variable;
return 0;
}
Upvotes: 3
Reputation: 63704
I suspect that you've created (and included) two headers that both have the same header guard
#ifndef FIRST_H_
#define FIRST_H_
Upvotes: 0