Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

gcc

libc

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.

like image 570
radiohead Avatar asked Feb 28 '18 20:02

radiohead


People also ask

Is libc dynamically linked?

However libc has not been linked in statically, only dynamically, so it is another failed attempt.

Does gcc depend on glibc?

Is it possible to compile a program using gcc without depending on glibc? Yes, there are alternative libc versions, such as Musl, uClibc, dietLibc, etc. See their documentation on how to use them. Your problem does not appear to be a GLIBC dependency, but rather a mismatch between your build and your target hosts.

Which libc does clang use?

One can also use clang with Microsoft Visual Studio C and C++ libraries.


1 Answers

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.

like image 190
llllllllll Avatar answered Sep 20 '22 03:09

llllllllll