不建议直接修改ld.so.conf,推荐的做法是在ld.so.conf.d目录下按程序名建立以.conf结尾的文件,把库路径写入即可。
#echo '/usr/local/gcc-4.8.5/lib64' > /etc/ld.so.conf.d/gcc4.8.5.conf
#ldconfig 更新加载动态库cache
出现以下提示,把这个文件删除了或忽略它
ldconfig: /usr/local/gcc-4.8.5/lib64/libstdc++.so.6.0.19-gdb.py is not an ELF file - it has the wrong magic bytes at the start.
在我实际使用中,到这一步都已经可以正常编译安装mariadb 10.2.12了。并不需要添加新gcc的环境变量。
alternatives [options] --install link name path priority [--slave link name path]... [--initscript service]
alternatives [options] --remove name path
alternatives [options] --set name path
alternatives [options] --auto name
alternatives [options] --display name
alternatives [options] --config name
具体用法,请man
#ll /usr/sbin/update-alternatives
lrwxrwxrwx. 1 root root 12 Dec 13 20:15 /usr/sbin/update-alternatives -> alternatives
语法说明:
还原gcc环境变量
#gcc -v
gcc version 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
#alternatives --install /usr/bin/gcc gcc /usr/local/gcc-4.8.5/bin/gcc 60
#alternatives --install /usr/bin/g++ g++ /usr/local/gcc-4.8.5/bin/g++ 60
#alternatives --install /usr/bin/c++ c++ /usr/local/gcc-4.8.5/bin/c++ 60
#alternatives --display gcc #gcc就是上面定义的名称
gcc - status is auto. #当前使用的模式
link currently points to /usr/local/gcc-4.8.5/bin/gcc #当前使用的链接
/usr/bin/gcc-4.4.7 - priority 50 #版本1的链接
/usr/local/gcc-4.8.5/bin/gcc - priority 60 #版本2的链接
Current `best' version is /usr/local/gcc-4.8.5/bin/gcc. #优先级高的选项 如何手动切换版本
自动切换配合--auto动作,并设置好优先级数字,数字越大,优先级越高。手动方式切换后,将会取消自动切换。
从手动切换回自动,alternatives --auto gcc
#alternatives --config gcc
There are 2 programs which provide 'gcc'.
Selection Command
-----------------------------------------------
*+ 1 /usr/bin/gcc-4.4.7
2 /usr/local/gcc-4.8.5/bin/gcc
Enter to keep the current selection[+], or type selection number: 2
---
#alternatives --config g++
There are 2 programs which provide 'g++'.
Selection Command
-----------------------------------------------
*+ 1 /usr/bin/g++-4.4.7
2 /usr/local/gcc-4.8.5/bin/g++
Enter to keep the current selection[+], or type selection number: 2
---
#alternatives --config c++
There are 2 programs which provide 'c++'.
Selection Command
-----------------------------------------------
*+ 1 /usr/bin/c++-4.4.7
2 /usr/local/gcc-4.8.5/bin/c++
Enter to keep the current selection[+], or type selection number: 2
#../cmake-3.10.2/configure --prefix=/usr/local/cmake-3.10.2
---------------------------------------------
CMake 3.10.2, Copyright 2000-2017 Kitware, Inc. and Contributors
Found GNU toolchain
C compiler on this system is: gcc
---------------------------------------------
Error when bootstrapping CMake:
Cannot find a C++ compiler supporting C++11 on this system.
Please specify one using environment variable CXX.
See cmake_bootstrap.log for compilers attempted.
这是使用新版本4.8.5 gcc编译cmake时的提示,已经没有报错了
#../cmake-3.10.2/configure --prefix=/usr/local/cmake-3.10.2
---------------------------------------------
CMake 3.10.2, Copyright 2000-2017 Kitware, Inc. and Contributors
Found GNU toolchain
C compiler on this system is: gcc
C++ compiler on this system is: g++ -std=gnu++1y
Makefile processor on this system is: gmake
g++ has setenv
g++ has unsetenv
g++ does not have environ in stdlib.h
g++ has stl wstring
g++ has <ext/stdio_filebuf.h>
编译MariaDB 10.2.12,因为这个版本明确指名需要使用gcc 的 c++11特性
可以明确的看到版本号并且调用成功
-- Running cmake version 3.10.2
-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for SHM_HUGETLB
-- Looking for SHM_HUGETLB - found
-- MariaDB 10.2.12