I wrote a .cpp full of functions and made a .h for it. How can I use header in other files without compiling the .cpp?
Printable View
I wrote a .cpp full of functions and made a .h for it. How can I use header in other files without compiling the .cpp?
you can't
Kurt
Your answer was like a hammer!
OK. I made a .lib
But there is a problem, linker generates an error and says you defined some vars in both files (.lib and the caller .cpp). And it is true, because there are some vars, const, etc defined in the header and the header was included in both .cpp and .lib.
What is the solution?
You DON'T define variables in the header, never ever. If you must have a reference toa variable there, declare it as extern:
X.h:
X.cpp:Code:extern int Y;
Code:int Y;
You mean make it extern, define it in both .lib and .cpp and recompile all?
Add "int Y" in one of the modules
Add "extern int Y" in all of the modules
The problem is that I defined an array in .h and I don't want to redefine it anywhere else.
There is only one solution then. Just use that header in only one compilation unit. :DQuote:
Originally Posted by siavoshkc
Kurt.
OK, I start another thread for solving this.