I have a project to be programmed on to my LPC 2148.(1 main.c and a couple f header files)
I have made a couple of header files.
I declared a constant in the first header file(say a.h )and included the file in the second header file (say b.h).
now when I compile,wherever i used the constant in b.h,I get the error telling me that the constant is undeclared even though it is declared in the header file which is included in this file.
How can I get around the following error ?I have a lot of constants declared over a set of 22 header files.
Any help is greatly appreciated.
Thanks in advance .
Maybe you could tell us what you mean by declare. And what you mean by define.
And you say you used the constant in one header file - are you placing code in header files?
I have the following lines in a .h file (named hci.h)
#define HCI_CMND_SOCKET 0x1001
and I wanted to use this in a file socket.c.
So I wrote something like this at the beginning of the socket.c file
#include "hci.h"
But the following error occurs
socket.c(228): error: #20: identifier "HCI_CMND_SOCKET" is undefined
Please note that hci.h is one of the files.There are a total of 22 files which are included in each other and in the final main.c file.Also I have included the following in the corresponding header files
#ifndef __HCI_H__ #define __HCI_H__
According to me the above error shouldnt occur. What do I do to prevent this?
Thanks for the reply
Make sure the compiler could find your header files properly. Where do the files locate? Can the compiler find them?
Make sure you stated #endif at the end of each header file.
If the comppiler couldn't find the file, there would be an error message to say so...
"Make sure you stated #endif at the end of each header file"
That should also give a specific error message
You say you've put that in "files" - did you really mean that plural?
These so-called "include guards" should be unique to the file in which they appear.
Maybe you've done your include guards wrong - and that's what's preventing your defines from being effective...?
Just a note here. These leading double underscores you used in your #define shouldn't be there, since it is part of a reserved name space intended for implementing the C standard library.
So even if you have seen lots of header files with a leading __ in the #define, you should consider to instead just use HCI_H or similar as symbol name.
Just to clarify this: that is not a declaration, which you had said you had put in your header file. That's a preprocessor definition.
"Something like that" might not suffice. So what did you actually write?
You're looking at a preprocessing problem. Almost invariably the solution to those is to capture and inspect the preprocessor's output. How to get at that is described in your compiler's manual.
In the case at hand, one of the things you need to look at very closely is which file named "hci.h" your compiler picked up by that #include line. A quick check whether you're even looking at the right file is to put a line like this
#error "If you do not see this message, you did not include this file!"
at the very beginning of your hci.h and see if you get the expected message when you compile again.
Dear Mystery IITian, Kindly dont expect the people to solve your problems if you are not willing to share them.
Kindly help us understand your problems clearly as you are facing them. this Reduces Human efforts, Time (yours and more importantly OURS) and yielding the best solution in the shortest amount of time.
Why secrecy? Ashamed of people making mockery "He calls himself an IITian and doesnt even know this stuff...