Keep in mind that the header file (
.h) only contains the
declaration of the function
mycode::foo()
, but the actual
implementation of that function is in a separate source file (.cpp). Therefore,
#include
'ing the header file only tells the compiler that the function exists, somewhere, but you still have to compile and link the actual
implementation too! It is done like this, so that the
declaration can be
#include
'd at many different places (source codes files) of your project, but the
implementation still only needs to exist at
one place.
With GCC and similar compilers, you do something like:
1 2 3
|
g++ -c -o test.o test.cpp
g++ -c -o namespace.o namespace.cpp
g++ -o test.exe test.o namespace.o
|
(first two lines compile the source code files, last line links the resulting object files together)