How to install c++ via yum command without using "Development Tools" group? - c++

I want to run c++ on my centos machine. My Google searches says that run yum group install "Development Tools" command but this downloads other packages too like bison,perl,automake, etc which is not required for my use-case and only increases my docker container size. Can someone suggest the necessary packages required to run c++ ?
TIA

The only necessary tool to "run" C++ (aka build C++) is a compiler:
sudo yum install gcc
echo "#include <iostream>" > main.cpp
echo "int main(){ std::cout << \"Hello World\" << std::endl; }" >> main.cpp
gcc main.cpp -o test -lstdc++
./test

Sure, you can:
sudo yum install gcc gcc-c++
This will install default gcc version supplied by your distro.
If you are on RHEL 7 and/or CentOS 7, the default gcc version is quite outdated (4.8.5), so you may want to install "devtoolset-N", which provide newer GCC versions, via Software Collections, for example look at this one. In there, in my experience, installing the devtoolset-N package will install the whole buch of stuff, similar to what groupinstall "Development Tools" does, so for Docker container it is good enough to only install devtoolset-N-toolchain. I also once needed devtoolset-N-libatomic-devel.

Related

How to build g++ 10/C++20 on WSL2?

I would like to try out the new features of C++20 on Windows 10 & WSL2. Since my ubuntu on WSL2 was very old (16), I followed these instructions:
sudo apt update -y # makes apt system itself up-to-date
sudo apt dist-upgrade -y # updates Ubuntu 18.04 packages to latest
sudo do-release-upgrade # performs the upgrade to Ubuntu 20.04
Midway thru these directions for building g++ 10, I execute
contrib/download_prerequisites
and I get this error:
error: You must run this script in the top-level GCC source directory
The problem line of code seems to be
[ -e ./gcc/BASE-VER ] \
|| die "You must run this script in the top-level GCC source directory"
The problem is that while there is a gcc directory, there is no BASE-VER directory.
Is there a better set of instructions I should use? Is there a bug in this script?
Thanks
Siegfried
Being unfamiliar with WSL2 I cannot be sure, but this looks to me like...
[ -e ./gcc/BASE-VER ] should be referring to gcc/$BASE_VER or some such. Does it look like such a directory exists?
Also those apt commands updated you to version 18.04 of Ubuntu. do-release-upgrade goes one version at a time, roughly speaking. Assuming (?) you are on a LTS release (16.04) it will bump yu up one major version to the 18.04 version (major version numbers are even - a fact I only just noticed and I have been using Ubuntu since vit started....)

How to install gcc/g++ 9 on CentOS 8 docker (centos:latest)

In order to use the C++17 include <filesystem> I need gcc-9 package in my centos docker.
By default centos:latest (aka 8) will install gcc 8.3.1 from the regular distro repo.
Is there any PPA, testing repo, whatever, where I can easily install a gcc-9 (or later) package (i.e. not build it from source)
Thanks !
note: need gcc-9 to have good C++17 <filesystem> support.
GCC 9 Release note:
Using the types and functions in <filesystem> does not require linking with -lstdc++fs now.
src: https://gcc.gnu.org/gcc-9/changes.html
note2: CMake 3.16* doesn't support any cxx_filesystem compiler feature AFAIK.
ref: https://cmake.org/cmake/help/latest/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html
note3: you can found log here: https://github.com/Mizux/KalistoUnpacker/runs/642516660?check_suite_focus=true
Simply use dnf
dnf -y install gcc-toolset-9-gcc gcc-toolset-9-gcc-c++
source /opt/rh/gcc-toolset-9/enable
ref: https://centos.pkgs.org/8/centos-appstream-x86_64/gcc-toolset-9-gcc-9.1.1-2.4.el8.x86_64.rpm.html
Note: source won't work inside a Dockerfile so prefer to use:
ENV PATH=/opt/rh/gcc-toolset-9/root/usr/bin:$PATH
or better
RUN dnf -y install gcc-toolset-9-gcc gcc-toolset-9-gcc-c++
RUN echo "source /opt/rh/gcc-toolset-9/enable" >> /etc/bashrc
SHELL ["/bin/bash", "--login", "-c"]
RUN gcc --version
this command work for me
dnf install gcc --best --allowerasing

how to install C++14 on RHEL 7.4

My question is similar to how to install gcc 4.9.2 on RHEL 7.4
But I'm trying to get C++14 support on Red Hat 7 so I can install mapnik.
I've tried:
# yum-config-manager --enable rhel-server-rhscl-7-rpms
Install gcc, g++ version 4.9.2 :
# yum install devtoolset-3-gcc-c++
Enabling gcc-4.9, g++-4.9 : $ scl enable devtoolset-3 bash
But I keep getting
C++ compiler does not support C++14 standard (-std=c++14), which is required. Please upgrade your compiler
The issue is that devtoolset-3 contains the c++11 standard. Making and installing GCC from source caused two GCC versions to exist together. The default being the c++11 version. In order to get the correct version of gcc I needed to install devtoolset-7 and make sure devtoolset-3 was superseded or removed.
Here is how I enabled it:
1. Install a package with repository for your system:
On RHEL, enable RHSCL repository for your system:
$ sudo yum-config-manager --enable rhel-server-rhscl-7-rpms
2. Install the collection:
$ sudo yum install devtoolset-7
3. Start using software collections:
$ scl enable devtoolset-7 bash
You can download GCC sources and build it.
Generally the process involve:
Download tar.gz with GCC source code, from here: https://ftp.gnu.org/gnu/gcc/
Configure, Make and install. You can look for documentation in their site on how to do it, specifically you can start here:
https://gcc.gnu.org/wiki/InstallingGCC

Installing gcc on linux

How to install gcc version 4.8 on centos or scientific linux operating systems which require yum for installing.
I tried to download gcc from https://ftp.gnu.org/gnu/gcc/gcc-4.8.2/ and then ran ./configure and then make. After running make it gives me the error: configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details.
Is there some way by which I may install gcc version 4.8 on linux using yum install
I tried:
1). I tried with yum --enablerepo=testing-2-devtools-6 install devtoolset-2-gcc devtoolset-2-gcc-c++ it gives me repository not found
2). yum group install "Development Tools". It gives me Package gcc-4.4.7-11.el6.x86_64 already installed and latest version
3). building it from scratch, you'll have to do ./contrib/download_prerequisites first to get MPFR, GMP and MPC in the GCC source tree, then make a separate directory and run /path/to/gcc/source/configure.
It gives:
configure: error: building out of tree but /home/Softwares/gcc-4.8.2
contains host-x86_64-unknown-linux-gnu
https://access.redhat.com/documentation/en-US/Red_Hat_Developer_Toolset/3/html/3.0_Release_Notes/DTS3.0_Release.html#Features
Install the Red Hat Developer Toolset 3.0 (or 2.X) in a way similar to what is described here. (Basically you use a repo someone else built for CentOS).
Google says to try
yum group install "Development Tools"
check out: http://www.cyberciti.biz/faq/centos-rhel-7-redhat-linux-install-gcc-compiler-development-tools/

Compile error in eclipse for c++

First of all, I'm new to Linux OS.
I installed ubuntu and eclipse and the c/c++ package.
I started a new project, that is the default project, "Hello World c++ project",
and when I run it, it's given me the erorr:
Description Resource Path Location Type
Program "g++" not found in PATH Preferences, C++/Build/Settings/Discovery, [CDT GCC Builtin Compiler Settings] options C/C++ Scanner Discovery Problem
What should I do?
Try to install all developer tools typing in console: sudo aptitude install build-essential. It will install g++, gcc and all libraries.
I had the same problem. Here's how I fixed it:
Run sudo sudo apt-get install build-essential to install the gcc, g++ and libraries.
Update the PATH environmental variable in the /etc/environment file adding /usr/bin/g++
Restart your VM or PC for this changes to take effect.