user1516425
user1516425

Reputation: 1571

Default libraries linked in by gcc?

Let's say I have a very simple C file (called foo.c):

int main()
{
   printf("foo");
   return 0;
}

Now I call gcc:

gcc foo.c

When I call gcc (with no options, as in the above example), what libraries are linked in by default and where are they located? (On Mac OS X 10.7)

Upvotes: 25

Views: 17806

Answers (3)

bhuwansahni
bhuwansahni

Reputation: 1844

The standard libraries are linked by default. they are located in /usr in linux machines

Upvotes: -2

Michael Burr
Michael Burr

Reputation: 340218

The -v option to gcc will cause it to dump information about the default options it will use including the library paths and default libraries and object files that will be linked in.

If you give the -Wl,--verbose option, gcc will pass the --verbose to the linker which will dump exactly where it's looking for libraries, including both failed and successful searches.

Combine both options, and you'll see exactly what libraries are linked in, and why they're being linked in.

gcc -v foo.c -Wl,--verbose

Upvotes: 29

Related Questions