Back to questionsWhat happens when these files are built with the command
JuniorTheoryCommon
What happens when these files are built with the command clang++ main.cpp?
// triple.h
int triple(int x);
// triple.cpp
#include "triple.h"
int triple(int x) { return x * 3; }
// main.cpp
#include "triple.h"
int main() { return triple(14); }Link error: nothing in this build defines triple
- Expecting
#include "triple.h"to bring intriple.cpp: it pastes only the header's text, andtriple.cppis compiled only when the build command names it. - Expecting a compiler error: the declaration from
triple.his enough to compile the call; only the linker looks for the body oftriple.
- Which command builds these files into one working program?
- How does the build system CMake help keep a source file from being left out?