Thread: Makefiles
View Single Post
Old 21st October 2008
ocicat ocicat is offline
Administrator
 
Join Date: Apr 2008
Posts: 3,318
Default

Quote:
Originally Posted by JMJ_coder View Post
With the class thing, adding it to the main.cpp, I would
Code:
#include "thing.h"
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
Code:
#include "thing.h"
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.

Last edited by ocicat; 21st October 2008 at 02:03 AM.
Reply With Quote