C #include and constants problem
I have these two files, functions.c and constants.h.
functions.c has this line:
#include "constants.h"
However, when I try to compile functions.c, functions.c functions can't find these constants from constants.c. These are const type constants. I know it's a very noobish problem, but I don't know the solution.
开发者_JAVA技巧EDIT: Files content (some of them):
functions.c:
#include <string.h>
#include "Directivas.h"
...
int hayDirectivaInclude(char* buffer) {
if (strncmp(include, buffer, longInclude) == 0)
return 1;
else
return 0;
}
constants.h:
const char include[10] = { '#', 'i', 'n', 'c', 'l', 'u', 'd', 'e', ' ', 0 };
const int longInclude = 9;
Your constants.h
must contain extern
references to the constants.
For example, suppose you had: const char* COOL_STRING = "Erandros is cool."
in constants.c. In order for functions.c
to know about this string, you must inform it of its existence by writing extern char* COOL_STRING;
somewhere, such as in constants.h
Are the constants declared in constants.h
? You should at least declare them there, or else the compiler won't know they exist when processing functions.c
.
see suppose you have declared some function in constants.h and its defination are in constants.c then when you are compiling function.c " just by including constants.h will not have include defination of those function . so it will give error...you need to compile both .c file wit together.
精彩评论