Gcc verson stream 9

Issues related to applications and software problems and general support
Post Reply
jeffsmith82
Posts: 13
Joined: 2018/11/29 14:29:36

Gcc verson stream 9

Post by jeffsmith82 » 2022/11/17 17:14:01

Seen that RHEL 9.1 is now out https://www.phoronix.com/news/Red-Hat-E ... -Linux-9.1 and that it now includes GCC 12.

Does anyone know if this refers to gcc-toolset-12-gcc or should I be able to use it form the "dnf module list". I'm currently using CentOS Stream 9 and thought this was a bit of a testing ground for some of this suff so should be there but only the toolset version is.

User avatar
jlehtone
Posts: 4203
Joined: 2007/12/11 08:17:33
Location: Finland

Re: Gcc verson stream 9

Post by jlehtone » 2022/11/17 19:08:00

The gcc-toolset-12 is a collection of packages that contains build tools, including GCC 12.

It is not a separate "stream", but continues the "Software Collection" style.
You can install them without removing the corresponding system packages.
You have to use the 'scl' command, e.g.
scl enable gcc-toolset-12 bash
(or something like that) to get bash session, where you can use tools from the toolset.

jeffsmith82
Posts: 13
Joined: 2018/11/29 14:29:36

Re: Gcc verson stream 9

Post by jeffsmith82 » 2022/11/18 09:28:30

Is there a way to have scl enabled for a service ? The boss has written a http server that you can issue commands to execute scripts that build our code. I could never get it to actually use the scl version so gave up.

User avatar
jlehtone
Posts: 4203
Joined: 2007/12/11 08:17:33
Location: Finland

Re: Gcc verson stream 9

Post by jlehtone » 2022/11/18 11:14:02

Yes.

As example, CentOS 7 has package 'rh-mariadb105-mariadb-server'.
It does supply files, like:

Code: Select all

/opt/rh/rh-mariadb105/service-environment
/usr/lib/systemd/system/rh-mariadb105-mariadb.service
/opt/rh/rh-mariadb105/enable
It is thus possible to systemctl start rh-mariadb105-mariadb without calling 'scl'.

The rh-mariadb105-mariadb.service contains (among other things):

Code: Select all

[Service]
# Load collections set to enabled for this service
EnvironmentFile=/opt/rh/rh-mariadb105/service-environment

# We want to start server only inside "scl enable" invocation
ExecStartPre=/usr/bin/scl enable $RH_MARIADB105_SCLS_ENABLED -- /usr/bin/scl_enabled rh-mariadb105

ExecStart=/opt/rh/rh-mariadb105/root/usr/libexec/mysqld-scl-helper enable $RH_MARIADB105_SCLS_ENABLED -- /opt/rh/rh-mariadb105/root/usr/libexec/mysqld --basedir=/opt/rh/rh-mariadb105/root/usr $MYSQLD_OPTS $_WSREP_NEW_CLUSTER

ExecStartPost=/usr/bin/scl enable $RH_MARIADB105_SCLS_ENABLED -- /opt/rh/rh-mariadb105/root/usr/libexec/mysql-check-upgrade

Code: Select all

and the /opt/rh/rh-mariadb105/service-environment explains a bit:
# Services are started in a fresh environment without any influence of user's
# environment (like environment variable values). As a consequence,
# information of all enabled collections will be lost during service start up.
# If user needs to run a service under any software collection enabled, this
# collection has to be written into RH_MARIADB105_SCLS_ENABLED variable
# in /opt/rh/rh-mariadb105/service-environment.
RH_MARIADB105_SCLS_ENABLED="rh-mariadb105"
In other words, systemd does not simply run "mysqld", it runs

Code: Select all

mysqld-scl-helper enable rh-mariadb105 mysqld
(I won't dig into 'mysqld-scl-helper' to see haw it differs from 'scl'.)

The crucial point is that the EnvironmentFile is sourced in order to modify the environment.

The 'scl' does source a file too, the /opt/rh/rh-mariadb105/enable that contains:

Code: Select all

# For binaries
export PATH="/opt/rh/rh-mariadb105/root/usr/bin:/opt/rh/rh-mariadb105/root/usr/sbin${PATH:+:${PATH}}"
# For header files
export CPATH="/opt/rh/rh-mariadb105/root/usr/include${CPATH:+:${CPATH}}"
# For libraries during build
export LIBRARY_PATH="/opt/rh/rh-mariadb105/root/usr/lib64${LIBRARY_PATH:+:${LIBRARY_PATH}}"
# For libraries during linking
export LD_LIBRARY_PATH="/opt/rh/rh-mariadb105/root/usr/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"
# For man pages; empty field makes man to consider also standard path
export MANPATH="/opt/rh/rh-mariadb105/root/usr/share/man:${MANPATH:-}"
# For Java Packages Tools to locate java.conf
export JAVACONFDIRS="/etc/opt/rh/rh-mariadb105/java${JAVACONFDIRS:+:}${JAVACONFDIRS:-}"
# For XMvn to locate its configuration file(s)
export XDG_CONFIG_DIRS="/etc/opt/rh/rh-mariadb105/xdg:${XDG_CONFIG_DIRS:-/etc/xdg}"
# For systemtap
export XDG_DATA_DIRS="/opt/rh/rh-mariadb105/root/usr/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
# For pkg-config
export PKG_CONFIG_PATH="/opt/rh/rh-mariadb105/root/usr/lib64/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}"
In principle, one could set all those in EnvironmentFile of a service, rather than call 'scl',
but then one has to maintain that file.

The /opt/rh/gcc-toolset-12/enable (in AlmaLinux 9) has:

Code: Select all

# General environment variables
export PATH=/opt/rh/gcc-toolset-12/root/usr/bin${PATH:+:${PATH}}
export MANPATH=/opt/rh/gcc-toolset-12/root/usr/share/man${MANPATH:+:${MANPATH}}
export INFOPATH=/opt/rh/gcc-toolset-12/root/usr/share/info${INFOPATH:+:${INFOPATH}}
# ??? We probably don't need this anymore.
export PCP_DIR=/opt/rh/gcc-toolset-12/root
# bz847911 workaround:
# we need to evaluate rpm's installed run-time % { _libdir }, not rpmbuild time
# or else /etc/ld.so.conf.d files?
rpmlibdir=$(rpm --eval "%{_libdir}")
# bz1017604: On 64-bit hosts, we should include also the 32-bit library path.
# bz1873882: On 32-bit hosts, we should include also the 64-bit library path.
# bz2027377: Avoid unbound variables
if [ "$rpmlibdir" != "${rpmlibdir/lib64/}" ]; then
  rpmlibdir32=":/opt/rh/gcc-toolset-12/root${rpmlibdir/lib64/lib}"
  rpmlibdir64=
else
  rpmlibdir64=":/opt/rh/gcc-toolset-12/root${rpmlibdir/lib/lib64}"
  rpmlibdir32=
fi
# Prepend the usual /opt/.../usr/lib{64,}.
export LD_LIBRARY_PATH=/opt/rh/gcc-toolset-12/root$rpmlibdir$rpmlibdir64$rpmlibdir32${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export PKG_CONFIG_PATH=/opt/rh/gcc-toolset-12/root/usr/lib64/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}
That is, something is prepended into PATH, MANPATH, INFOPATH, PCP_DIR, LD_LIBRARY_PATH, and PKG_CONFIG_PATH.

Your automation does not run 'man' or 'info', does it? Therefore, the service won't need those two paths.

The httpd.service (on CentOS 7) does set EnvironmentFile=/etc/sysconfig/httpd. The version on el9 might not.
RHEL documentation about systemd does tell how to override bits of existing unit file.


PS: You are not running CentOS Stream on production, are you?
I'd rather (well, I do) run AlmaLinux 9 (although Rocky Linux 9 is just as good).

jeffsmith82
Posts: 13
Joined: 2018/11/29 14:29:36

Re: Gcc verson stream 9

Post by jeffsmith82 » 2022/11/18 13:34:30

Thanks for the in depth response, will give that a try and see if i can make it work.

Post Reply