Fedora 27环境下安装版本<6的gcc与g++求助
Hey there, I’ve been in your exact situation before—dealing with compiler version conflicts when building TensorFlow GPU can be a real headache. Let’s walk through how to install and switch to an older gcc/g++ version (below 6, we’ll use gcc 5 as an example) on your Fedora 27 system:
Fedora’s repositories still host older compiler versions, so we can grab them directly with dnf:
- Run this command to install gcc 5 and g++ 5:
sudo dnf install gcc5 gcc-c++5 - Verify the installation worked by checking the versions:
gcc5 --versiong++5 --version
Instead of overwriting your system’s default gcc 7 (which might break other tools), we’ll use update-alternatives to switch between versions safely:
- Add gcc 5 and gcc 7 as alternative options:
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc5 10sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc7 20 - Do the same for g++:
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++5 10sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++7 20 - Switch to gcc 5 as the default:
sudo update-alternatives --config gcc
You’ll see a list of options—enter the number corresponding to/usr/bin/gcc5and hit enter. - Repeat for g++:
sudo update-alternatives --config g++
Run these commands to make sure your default compiler is now the older version:gcc --versiong++ --version
You should see output showing gcc 5.x instead of 7.3.1.
- If you need to switch back to gcc 7 later, just re-run the
update-alternatives --configcommands and select the gcc7 option. - To make sure TensorFlow uses the correct compiler during build, set these environment variables before starting the compilation process:
export CC=/usr/bin/gcc5export CXX=/usr/bin/g++5
内容的提问来源于stack exchange,提问作者DEVENDRA MEENA

