PDA

View Full Version : VC++ 6 Include Source Files



03-15-2002, 12:42 PM
I added "light.c" to a project via "Add to Project>>Files" And then I included in the main program by stating "#include "light.c"" so I should be able to use functions from the file. But...
it says that it cannot find the file (light.c) when I try to compile. So how do I get the compiler to recognize this file?

zeckensack
03-15-2002, 03:43 PM
That's what headers are for. Sheesh.
These are really coding basics but I'm in a good mood right now, so I'll try and explain it anyway:

Create a header file with all the function declarations in it.

void my_wonderful_function(int nice,int better,float great);

You save that as, say, light.h and insert into your headers section in the VC workspace.

Then, in light.c, and everywhere else where you want to have access to that function, insert #include "light.h" at the top.

You only need to implement the function once (probably in light.c, eh?) but you can access it everywhere you include the header.

But please, please, please, this is way off topic, try something like this board (http://www.cprogramming.com/board.html) next time.

chxfryer
03-17-2002, 07:22 AM
also in the header...
at the very top put something like
#ifndef LIGHT_H
#define LIGHT_H

code goes here

#endif

otherwise it will try to compile it many times and you will get errors. I used to always write all my code in one file because I didnt know about these 3 lines of code.