Quote:
Originally Posted by JMJ_coder
With the class thing, adding it to the main.cpp, I would and then would I link in the Makefile
Code:
a.out: main.o thing.o
g++ main.o thing.o
|
Correct.
Quote:
or would the simple automatically link what needs to be linked?
|
The
#include preprocessor directive passes no information on to the linker. The
#include command is simply used to supply the compiler sufficient information for it to create the corresponding object file. No more.
I suspect you may be finding the following fact confusing & possibly a cause for some misunderstanding: functions like
printf() appear to
only require inclusion of
stdio.h, & the linker magically links in the appropriate library. This is the correct behavior because the standard
libc library is linked into applications
by default. All functions found in
libc are accessible within an application without
explicitly telling the linker to resolve references to this particular library. This isn't done because of the
#include, or by the fact that the
#include statement is done with angle brackets
(#include <stdio.h>). The code for
printf() is magically linked into the application because
libc is linked into the application
by default.