skip to Main Content

Rocky Linux is a free distribution that repackages each release of RHEL (Red Hat Enterprise Linux). It is what CentOS used to be.

On AWS there are Official releases of Rocky Linux 8 Green Obsidian (currently 8.6 = RHEL 8.6) and Rocky Linux 9 Blue Onyx (currently 9.0 = RHEL 9.0).

I am using g++ (gcc).

On Rocky Linux 8.6: g++ (GCC) 8.5.0 20210514 (Red Hat 8.5.0-10)

On Rocky Linux 9.0: g++ (GCC) 11.2.1 20220127 (Red Hat 11.2.1-9)

Building with dynamic linking works fine.
Making a statically linked build works fine elsewhere (e.g. Ubuntu).

But it seems some static libraries are missing on the Rocky Linux platforms (8 or 9), which leads to error messages when trying to build with -static linking.

/usr/bin/ld: cannot find -lstdc++
/usr/bin/ld: cannot find -lm
/usr/bin/ld: cannot find -lc

Looking on the whole system for any lib*.a for static linking, I do find

/usr/lib/gcc/x86_64-redhat-linux/8/32/libstdc++.a

However, I believe that is for "32" bit builds, not 64. I do find libm.so and libc.so for dynamic linking, but there are no libm.a or libc.a libraries for static linking.

Using yum, I don’t find any packages that are or that provide libstdc++-static.

gcc.x86_64 and glibc-devel.x86_64 are already installed.

What is needed to get the necessary static libraries for a static build?

Thanks in advance!

2

Answers


  1. Chosen as BEST ANSWER

    Danila Vershinin provided an answer that enables the relevant repo just for the specific install.

    As another option, if you want the repo to remain enabled for some reason (e.g. for the sake of multiple installs or operations), one could also do the following.

    Rocky Linux 9

    sudo dnf config-manager --set-enabled crb
    

    Rocky Linux 8

    sudo dnf config-manager --set-enabled powertools
    

    Then one could use any number of commands that need the repo to be enabled.

    sudo dnf install -y libstdc++-static
    

    ...

    sudo dnf install -y glibc-static
    

  2. The libstdc++-static package is in the CRB (CodeReady Builder) repository.
    You can install like this:

    Rocky Linux 9

    dnf --enablerepo=crb install libstdc++-static
    

    Rocky Linux 8

    dnf --enablerepo=powertools install libstdc++-static
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search