Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default libraries linked in by gcc?

Tags:

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)

like image 765
user1516425 Avatar asked Jul 14 '12 04:07

user1516425


People also ask

Which gcc option is used to link the library?

The -l option tells gcc to link in the specified library.

Where are gcc libraries?

The standard system libraries are usually found in the directories '/usr/lib' and '/lib'. For example, the C math library is typically stored in the file '/usr/lib/libm. a' on Unix-like systems.

How are libraries linked in C?

Shared libraries (also called dynamic libraries) are linked into the program in two stages. First, during compile time, the linker verifies that all the symbols (again, functions, variables and the like) required by the program, are either linked into the program, or in one of its shared libraries.

Does gcc automatically link?

When the -fsanitize=thread option is used to link a program, the GCC driver automatically links against libtsan . If libtsan is available as a shared library, and the -static option is not used, then this links against the shared version of libtsan .


2 Answers

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 
like image 192
Michael Burr Avatar answered Sep 22 '22 04:09

Michael Burr


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

like image 27
ForEveR Avatar answered Sep 25 '22 04:09

ForEveR