binutils and the error ld: unrecognized option ‘–no-dynamic-linker’

Author:

Yet another bites of an old bintuils installed in the system, which leads to an error and failed a building of glibc this time. The last time it was a kernel building failure, check out here – . Most of the time, these kind of errors occurs when upgrading an old system, so as soon as building the new binutils package with emerge it is mandatory to remove the old one to minimize compiling errors of this sort.

main menu
building failure

This time the error under Gentoo system is (but it could happen in any system with old and new binutils!):

/usr/lib/gcc/x86_64-pc-linux-gnu/11/../../../../x86_64-pc-linux-gnu/bin/ld: unrecognized option '--no-dynamic-linker'
/usr/lib/gcc/x86_64-pc-linux-gnu/11/../../../../x86_64-pc-linux-gnu/bin/ld: use the --help option for usage information
collect2: error: ld returned 1 exit status

To fix the error simply remove the (all) old binutils package(s) with emerge command:

[root@srv ~]# emerge -vaC =binutils-2.25-r1
 * This action can remove important packages! In order to be safer, use
 * `emerge -pv --depclean <atom>` to check for reverse dependencies before
 * removing packages.

>>> These are the packages that would be unmerged:

 sys-devel/binutils
    selected: 2.25-r1 
   protected: none 
     omitted: 2.41-r1 

All selected packages: =sys-devel/binutils-2.25-r1

>>> 'Selected' packages are slated for removal.
>>> 'Protected' and 'omitted' packages will not be removed.

Would you like to unmerge these packages? [Yes/No] yes
>>> Waiting 5 seconds before starting...
>>> (Control-C to abort)...
>>> Unmerging in: 5 4 3 2 1
>>> Unmerging (1 of 1) sys-devel/binutils-2.25-r1...
No package files given... Grabbing a set.
<<<          obj /usr/x86_64-pc-linux-gnu/binutils-bin/2.25/strip
<<<          obj /usr/x86_64-pc-linux-gnu/binutils-bin/2.25/strings
<<<          obj /usr/x86_64-pc-linux-gnu/binutils-bin/2.25/size
<<<          obj /usr/x86_64-pc-linux-gnu/binutils-bin/2.25/readelf
......
......


Note, under Gentoo Linux system, there is a second solution – to choose which binutils to use the system when building packages. Use eselect command to choose the active binutils for building:

[root@srv ~]# eselect binutils list
 [1] x86_64-pc-linux-gnu-2.37_p1
 [2] x86_64-pc-linux-gnu-2.38
 [3] x86_64-pc-linux-gnu-2.39 *
 [4] x86_64-pc-linux-gnu-2.41

The active one is [3]x86_64-pc-linux-gnu-2.39. To select the latest one use eselect, again:

[root@srv ~]# eselect binutils set 4
 * Switching to x86_64-pc-linux-gnu-2.41 ...                                                                                                                                           [ ok ]

 * Please remember to run:

 *   # . /etc/profile

[root@srv ~]# . /etc/profile

[root@srv ~]#  eselect binutils list
 [1] x86_64-pc-linux-gnu-2.37_p1
 [2] x86_64-pc-linux-gnu-2.38
 [3] x86_64-pc-linux-gnu-2.39
 [4] x86_64-pc-linux-gnu-2.41 *

Here is the whole error output

Building error caused by the old version of binutils.

x86_64-pc-linux-gnu-gcc -m32 -mfpmath=sse -mstackrealign -march=core2 -pipe -O2 -fcf-protection=none -Wl,-O1 -o /var/tmp/portage/sys-libs/glibc-2.38-r2/work/build-x86-x86_64-pc-linux-gnu-nptl/support/test-run-command -nostdlib -nostartfiles -static -static-pie   -Wl,-O1  /var/tmp/portage/sys-libs/glibc-2.38-r2/work/build-x86-x86_64-pc-linux-gnu-nptl/csu/rcrt1.o /var/tmp/portage/sys-libs/glibc-2.38-r2/work/build-x86-x86_64-pc-linux-gnu-nptl/csu/crti.o `x86_64-pc-linux-gnu-gcc -m32 -mfpmath=sse -mstackrealign -march=core2 -pipe -O2 -fcf-protection=none -Wl,-O1  --print-file-name=crtbeginS.o` /var/tmp/portage/sys-libs/glibc-2.38-r2/work/build-x86-x86_64-pc-linux-gnu-nptl/support/test-run-command.o /var/tmp/portage/sys-libs/glibc-2.38-r2/work/build-x86-x86_64-pc-linux-gnu-nptl/elf/static-stubs.o /var/tmp/portage/sys-libs/glibc-2.38-r2/work/build-x86-x86_64-pc-linux-gnu-nptl/support/libsupport_nonshared.a -Wl,-z,now -Wl,--start-group /var/tmp/portage/sys-libs/glibc-2.38-r2/work/build-x86-x86_64-pc-linux-gnu-nptl/libc.a -lgcc  -Wl,--end-group `x86_64-pc-linux-gnu-gcc -m32 -mfpmath=sse -mstackrealign -march=core2 -pipe -O2 -fcf-protection=none -Wl,-O1  --print-file-name=crtendS.o` /var/tmp/portage/sys-libs/glibc-2.38-r2/work/build-x86-x86_64-pc-linux-gnu-nptl/csu/crtn.o
/usr/lib/gcc/x86_64-pc-linux-gnu/11/../../../../x86_64-pc-linux-gnu/bin/ld: unrecognized option '--no-dynamic-linker'
/usr/lib/gcc/x86_64-pc-linux-gnu/11/../../../../x86_64-pc-linux-gnu/bin/ld: use the --help option for usage information
collect2: error: ld returned 1 exit status
make[2]: *** [../Rules:290: /var/tmp/portage/sys-libs/glibc-2.38-r2/work/build-x86-x86_64-pc-linux-gnu-nptl/support/test-run-command] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: Leaving directory '/var/tmp/portage/sys-libs/glibc-2.38-r2/work/glibc-2.38/support'
make[1]: *** [Makefile:485: support/others] Error 2
make[1]: Leaving directory '/var/tmp/portage/sys-libs/glibc-2.38-r2/work/glibc-2.38'
make: *** [Makefile:9: all] Error 2
make: Leaving directory '/var/tmp/portage/sys-libs/glibc-2.38-r2/work/build-x86-x86_64-pc-linux-gnu-nptl'
 * ERROR: sys-libs/glibc-2.38-r2::gentoo failed (compile phase):
 *   emake failed
 * 
 * If you need support, post the output of `emerge --info '=sys-libs/glibc-2.38-r2::gentoo'`,
 * the complete build log and the output of `emerge -pqv '=sys-libs/glibc-2.38-r2::gentoo'`.
 * The complete build log is located at '/var/tmp/portage/sys-libs/glibc-2.38-r2/temp/build.log'.
 * The ebuild environment file is located at '/var/tmp/portage/sys-libs/glibc-2.38-r2/temp/environment'.
 * Working directory: '/var/tmp/portage/sys-libs/glibc-2.38-r2/work/glibc-2.38'
 * S: '/var/tmp/portage/sys-libs/glibc-2.38-r2/work/glibc-2.38'

>>> Failed to emerge sys-libs/glibc-2.38-r2, Log file:

>>>  '/var/tmp/portage/sys-libs/glibc-2.38-r2/temp/build.log'

 * Messages for package sys-libs/glibc-2.38-r2:

 * After upgrading glibc, please restart all running processes.
 * Be sure to include init (telinit u) or systemd (systemctl daemon-reexec).
 * Alternatively, reboot your system.
 * (See bug #660556, bug #741116, bug #823756, etc)

 * Messages for package sys-libs/glibc-2.38-r2:

 * ERROR: sys-libs/glibc-2.38-r2::gentoo failed (compile phase):
 *   emake failed
 * 
 * If you need support, post the output of `emerge --info '=sys-libs/glibc-2.38-r2::gentoo'`,
 * the complete build log and the output of `emerge -pqv '=sys-libs/glibc-2.38-r2::gentoo'`.
 * The complete build log is located at '/var/tmp/portage/sys-libs/glibc-2.38-r2/temp/build.log'.
 * The ebuild environment file is located at '/var/tmp/portage/sys-libs/glibc-2.38-r2/temp/environment'.
 * Working directory: '/var/tmp/portage/sys-libs/glibc-2.38-r2/work/glibc-2.38'
 * S: '/var/tmp/portage/sys-libs/glibc-2.38-r2/work/glibc-2.38'

Leave a Reply

Your email address will not be published. Required fields are marked *