java
java

Reputation: 1165

stdio.h - whats the name of libfile and where can I find it Linux

I have a question about stdio.h in c-language.

well - this contains only the function-prototypes of the standard input- and output-streams. But there must be a libfile (objectfile) for this standard input- and output, right?

But what is its name and in which folder is it residing in Linux (ubuntu)?

Upvotes: 1

Views: 703

Answers (2)

cnicutar
cnicutar

Reputation: 182639

If I compile a simple hello world C program I get this:

% ldd easy
linux-vdso.so.1 =>  (0x00007fffcc9fe000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4a90eb6000)
/lib64/ld-linux-x86-64.so.2 (0x00007f4a91299000)

Why does it need libc ?

% nm easy
...
000000000040052d T main
             U printf@@GLIBC_2.2.5

The symbol printf is being provided by glibc. nm shows a printf symbol is being provided by that object:

% nm -D /lib/x86_64-linux-gnu/libc.so.6 | grep printf
...
00000000000542f0 T printf
0000000000109dc0 T __printf_chk
000000000004f1d0 T __printf_fp

Alternatively you can ask ldd to print debugging info:

% LD_DEBUG=bindings ./easy 2>&1 | grep printf
    17922:  binding file ./easy [0] to /lib/x86_64-linux-gnu/libc.so.6 [0]:\ 
    normal symbol `printf' [GLIBC_2.2.5]

Upvotes: 3

gipi
gipi

Reputation: 2515

It depends on which implementation of the standard library you use, but if you are mainstream and compile with gcc you can find the path of an library used to link with

$ gcc -print-file-name=libc.so /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/libc.so

Take into account that you can have more than one implementation installed in your system.

Upvotes: 1

Related Questions