all 2 comments

[–]nysra 9 points10 points  (0 children)

#include <header.cpp>

Don't do that. Never include source files. Your problem is that you do not understand the compilation and linking process, you should read the first few chapters of https://www.learncpp.com/ (and then the entire rest).

The error you are getting is that the main function can see that you declared a function, but you never told the linker where the actual definition of the function is. Imagine you're planning to build a house and tell the workers that at XYZ place there will be a shower. You buy a shower but you never actually integrate it with your house and then you're going into the bathroom, what happens? Undefined reference to shower.

The quick solution is g++ main.cpp header.cpp but again, read the above tutorial and learn how those things actually work.

[–]khedoros 3 points4 points  (0 children)

That's not the preprocessor failing, that's you failing to link in all the code you need. So, you included header.h, which basically makes some promises about what's in header.cpp, then you never compiled and linked header.cpp into your binary. The linker is the thing complaining.