Default libraries linked in by gcc?

14,798

Solution 1

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

Solution 2

ldd binary_name. http://www.opennet.ru/man.shtml?topic=ldd&category=1&russian=2

Share:
14,798

Related videos on Youtube

user1516425
Author by

user1516425

Updated on June 22, 2022

Comments

  • user1516425
    user1516425 almost 2 years

    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)

  • Kevin Grant
    Kevin Grant almost 12 years
    Note he said Mac OS X 10.7, where there is no ldd. The equivalent is otool -L.
  • user1516425
    user1516425 almost 12 years
    On my mac, ld says that --verbose is an unrecognized option
  • Michael Burr
    Michael Burr almost 12 years
    @user1516425: oh - when I see gcc, I just assume that GNU ld is involved. Looking at some docs for the Xcode linker, developer.apple.com/library/mac/#documentation/Darwin/Refere‌​nce/…, you might want to see if the -t linker option will do the trick. Some other options to consider can be found under the "Options for introspecting the linker" heading on that page.