I am using gcc compiler and ubuntu 12.04 OS. I want to know where can I find the object file and under which directory, which contains the definition of printf function. Again I am not looking for the header file which contains prototype but the object file which contains the actual definition.
Are you looking for the object file or the source file?
The .o object file is stored within a library, libc.so
. On most Linux distros, this file is located at /lib/libc.so
. On Ubuntu 11 and 12, as a part of multiarch support, the contents of /lib have been moved to /lib/i386-linux-gnu
and /lib/x86_64-linux-gnu
.
You can get the individual object file by using the ar
(archive) command that was used to create the library with the x
(extract) option:
ar x libc.a stdio.o
This doesn't seem very useful, though, so I'm guessing that you actually want the source file and not the object file. For that, you'd install the glibc package, which contains printf.c (which calls vprintf, which calls vfprintf, which contains the actual code for printf).
This source can be browsed on Launchpad. It's pretty complicated, and stretches well over 2000 lines of code.
objdump + some options | grep printf
(3) See GCC documentation and try it. –
Bowra I found the exact answer to first two questions of mine -
To list all object files present in libc we use following commands:
x86_64 system: $ ar -t /usr/lib/x86_64-linux-gnu/libc.a
i386 system: $ ar -t /usr/lib/i386-linux-gnu/libc.a
To find out which object file contain printf function run this command under /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu or directory:
$ nm -o libc.a | grep -w printf
Still working on to find the correct answer.
nm
is a good alternative to objdump
when you're dealing with libraries. –
Bowra © 2022 - 2024 — McMap. All rights reserved.
libc
. What exactly are you looking for? As in are you looking for the definition in the source or the library which contains it on your machine? – Kean