0

I understand the difference between

#include "xyz"

and

#include <xyz>

in terms of what location is searched in each case.

I would like to know whether there is an ordering according to which searching and linking is done. Are files using

#include "xyz" //as this is done in current working directory

linked before linking of files using

#include <xyz>
anubhav
  • 111
  • 3
  • 11

3 Answers3

2

Preprocessor includes have nothing to do with linking. This is a common misconception.

There is no assumption anywhere that one include corresponds to something being linked. Notice that the standard library has lots of headers, but generally only consists of a single library when the linking happens.

With e.g. gcc (and most other compilers) you can compile a C file first, then compile a bunch of other C files, then finally do the linking of all the object files with any required external libraries. When you do the linking, you're operating on already-compiled files (object files and libraries); these files know nothing about the order in which the preprocessor directives appeared in the original source, that is long gone.

unwind
  • 378,987
  • 63
  • 458
  • 590
1

#include "file" will search in current directory before searching in include path. There is no mechanism to specify the order of linking of object files.

Steephen
  • 13,137
  • 6
  • 34
  • 44
1

#include file directive tells the preprocessor to treat the contents of a specified file as if it appears in the source program at the point where the directive appears.

It is not related to linking.

Alper
  • 12,334
  • 2
  • 30
  • 40