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?
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?
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
you can't
Kurt
Your answer was like a hammer!
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
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?
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
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;
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
You mean make it extern, define it in both .lib and .cpp and recompile all?
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
Add "int Y" in one of the modules
Add "extern int Y" in all of the modules
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
The problem is that I defined an array in .h and I don't want to redefine it anywhere else.
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
There is only one solution then. Just use that header in only one compilation unit.Originally Posted by siavoshkc
Kurt.
OK, I start another thread for solving this.
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C