External variables of a C object file are global variables of another object file.
When all needed object files, either true object file (.o) or object files stored in libraries (.a or .so or ....) are linked together to create an executable, there is no more external variables but only global variables of all the needed objects.
Note that when linking to create an executable using a C compiler, some libraries are silently added (libC.a and others maybe) containing commonly used "external" variables like (stdin, stdout, stderr, errno ...).
If some external variables are not found in any object file, the linker failed to create an executable.
If you want to see some more examples open the /usr/include/stdio.h file. And check out the definitions of file operations.printfs etc.
e.g.(from stdio.h)
extern FILE *fopen(const char *, const char *);
extern FILE *freopen(const char *, const char *, FILE *);
When you include a header file you also include the extern defintion. When the file is compiled with the C-library the extern defintions are resolved by the global variables/functions present in the C-library.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.