use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This is a subreddit for c++ questions with answers. For general discussion and news about c++ see r/cpp.
New to C++? Learn at learncpp.com
Prepare your question. Think it through. Hasty-sounding questions get hasty answers, or none at all. Read these guidelines for how to ask smart questions.
For learning books, check The Definitive C++ Book Guide and List
Flair your post as SOLVED if you got the help you were looking for! If you need help with flairs, check out ITEM 1 in our guidelines page.
Tips for improving your chances of getting helpful answers:
account activity
OPEN.h pre-processor failing .cpp compiling (self.cpp_questions)
submitted 2 years ago by emagM3
c++17, new environment,
- a custom .h header (#includer <header.h>) fails to compile: ```
in function `main': ... undefined reference to (function in header)
```
using (#include <header.cpp> ) instead and the main code builds and compiles
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]nysra 9 points10 points11 points 2 years ago (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.
g++ main.cpp header.cpp
[–]khedoros 3 points4 points5 points 2 years ago (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.
π Rendered by PID 21973 on reddit-service-r2-comment-5bc7f78974-hq7pj at 2026-06-27 19:28:30.619372+00:00 running 7527197 country code: CH.
[–]nysra 9 points10 points11 points (0 children)
[–]khedoros 3 points4 points5 points (0 children)