Go Down

Topic: What is the Minimum Requirements for a Library Folder (Read 534 times) previous topic - next topic


Yes you can do that but there is a danger if you use the .h file in multiple places (multiple files) then you will get duplicate symbols.

don't the scope rules apply?
and where they don't the #ifdef construction takes care of redeclaration?

redeclaration is indeed fixed by the include guards. The problem is that, since the header file is pasted right into multiple compiled files, two files both declare the same functions, so the linker doesn't know which one to use.

Nick Gammon

The #ifdef only guards against nested includes.

If a.cpp and b.cpp both include foo.h and foo.h has an implementation (not just a function prototype) for function bar, then the linker will complain about duplicate implementations of bar.

But if you move the implementation into a .cpp file, the .cpp file is only compiled once, and this won't be a problem.


Thanks for explaining (never encountered this problem but still good to know)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up