radiohead
radiohead

Reputation: 449

Does gcc links to libc.a or libc.so by default?

I am using gcc 5.4.0 on Ubuntu 16.04 64 bit. When I compile a program:

gcc -o prog prog.c

GCC automatically links to the C standard library, so I don't have to specifically do that.

  1. How can I see which C library does gcc link against to, libc.a or libc.so, or something else?
  2. In what circumstance does it link to libc.so? Does libc.so need to be specified at run time like other shared libraries?

Thanks in advance.

Upvotes: 6

Views: 3881

Answers (1)

llllllllll
llllllllll

Reputation: 16444

How can I see which C library does gcc links against to, libc.a or libc.so, or something else?

You can use ldd command to see all linked shared libraries. If libc.so is found, it's dynamic linking.

In what circumstance does it links to libc.so?

gcc uses dynamic linking and links to libc.so by default. If you want static linking, pass -static flag.

Does libc.so need to be specified at run time like other shared libraries?

Normally no, since it's configured by compiler automatically.

Upvotes: 8

Related Questions