8

As titled, is binutils contained in gcc for Centos Linux? If I install gcc rpm package, is there need to install binutils also? What's more, are gcc and g++ both installed by default in Centos?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
jiafu
  • 6,338
  • 12
  • 49
  • 73
  • Can you do `binutils --version` to check? – Fiddling Bits Jan 19 '14 at 06:47
  • without binutils you won't be able to run any program. – rakib_ Jan 19 '14 at 07:35
  • 1
    @rakib: no, you can run programs without `binutils` but you cannot compile them. – Basile Starynkevitch Jan 19 '14 at 08:12
  • 1
    @BasileStarynkevitch Well, whenever we run a program loader loads the required shared libraries (.so files) and that loader program is part of `binutils`, then how can it's possible to run program without binutils? This is what I know so far, am I wrong? – rakib_ Jan 19 '14 at 08:17
  • 2
    But the dynamic loader (`/lib/ld-linux.so*`) is provided by the `libc` package, not by `binutils`; you could remove the `binutils` package and still be able to use your Linux system (e.g. the browser or the text processor). – Basile Starynkevitch Jan 19 '14 at 08:18
  • @BasileStarynkevitch thanks for clarifying. I build Linux from scratch, that time on I build `binutils` as the first package (IIRC) and whenever we install OS `binutils` got installed first and that's where my confusion came from. Moreover I thought dynamic loader is part of `binutils`. – rakib_ Jan 19 '14 at 08:26

1 Answers1

9

The gcc package probably contains the compiler proper, e.g. files /usr/bin/gcc and directory /usr/lib/gcc/x86_64-linux-gnu/4.8/ (which contains the cc1 executable).

The /usr/bin/gcc program starts cc1 (or cc1plus etc...) to compile your source code *.c, and also as to translate cc1-generated assembly code (produced by cc1) into object file *.o, and at last ld to link.

Compile once with gcc -v to understand what is happening, it would show the really executed binaries. Notice that gcc is only a driving program (starting other executables like cc1, as, ld ...)

The as and ld programs are provided by binutils -which is needed to compile.

So the binutils package is a required dependency for the gcc package (with many other dependencies, probably including libc and libc-devel, but if you really want you could use some other libc like MUSL libc; the libc is generally providing the dynamic linker like /lib/ld-linux.so*).

Learn how to use rpm (on Centos, or dpkg on Ubuntu & Debian) to query the dependencies between packages.

For development you probably want some other packages. Debian has the build-essential virtual package. Probably CentOS has an equivalent. And you'll surely want to use some libraries (and you want the development packages for them, e.g. on Debian libcurl4-gnutls-dev to develop with the libcurl HTTP client library). See also this answer (for Ubuntu and Debian, but you can adapt it for CentOS).

In 2021 you want to use GCC 10 at least, as g++ -Wall -Wextra -g and you could decide to code your own GCC plugin (checking some coding rules in your C++ code; you also want to document your coding conventions by writing). Be aware of the rule of five.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • @Basile Starynkevitch - does `gdb` is use the `binutils` - meaning, if I wish to be able to use `gdb` on some platform - do I have to have the `binutils` related programs (`ar`, `as`, `nm`, `ld` and the like also installed on the same platfrom? – Guy Avraham Aug 01 '23 at 07:29