Installing gcc 4.8 on Debian

2020-02-02 17:47发布

I want to start playing around with some of the newer C++11 features and it appears that the best support for this is with gcc 4.8, and Squeeze ships with 4.4.5.

However, I don't want to cause any "damage" to my current setup. What's the best way to get both versions of gcc running side-by-side? I'm concerned mostly at the large number of dependencies and that taking them all in to my current system may render it unstable.

Has anyone managed to do this, and what are the steps involved?

Failing that, I'll probably just create a VM and run an "unstable" Debian under that but it's a less-than-ideal solution.

标签: gcc c++11 debian
5条回答
唯我独甜
2楼-- · 2020-02-02 17:55

I had the same problem, and didn't want to fully upgrade to testing.

Jessie (testing) now contains g++-4.8 which is compliant with C++11.

I used apt-pinning in the following way:

A source to jessie was added to /etc/apt/sources.list:

deb http://ftp.uk.debian.org/debian/ jessie main non-free contrib

/etc/apt/preferences was edited as such:

Package: *
Pin: release n=wheezy
Pin-Priority: 900

Package: gcc*
Pin: release n=jessie
Pin-Priority: 910

Then,

$ sudo aptitude update
$ sudo aptitude install gcc/jessie

At which point I selected the second presented option to resolve dependencies fully.

查看更多
够拽才男人
3楼-- · 2020-02-02 17:57

Debian has the package under the name gcc-4.8 (or for the c++ compiler, g++-4.8). Installing those packages will not mess up your OS, as long as you do not rename it to g++. The package is listed as experimental though.
Information on the package is here.

Update: g++-4.8 is now in testing, but an updated package is in unstable

查看更多
男人必须洒脱
4楼-- · 2020-02-02 18:06

Quick ones:

  1. Just upgrade to testing, it is rock-solid and offers you several concurrent gcc versions. Similar for Ubuntu, on 12.10 I have gcc/g++ 4.4, 4.5, 4.6 and 4.7 in parallel.

  2. Try the Debian backports archive, it may have a port of gcc 4.8.

  3. Use virtualization: I prefer libvirt / kvm which is incredibly lightweight on Linux as it is kernel based. My amd64 server has two other 32 bit installations for that very reason.

  4. Not really a SO question...

查看更多
狗以群分
5楼-- · 2020-02-02 18:10

If you install GCC from source just make sure you don't install it to /usr and it won't mess anything up. If you install it as your own user, not root, then there is zero chance of messing up the system.

See http://gcc.gnu.org/wiki/InstallingGCC for the almost-idiot-proof minimal configuration.

I have various versions built as my user and installed in ~/gcc/4.X for various X.

The only thing to be aware of using that set up is that the shared libraries for the new version aren't in the dynamic linker's default search path, so you need to use LD_LIBRARY_PATH or some other solution to ensure executables find the libs from 4.8, see the libstdc++ FAQ and the page it links to in the manual

I use a wrapper script call g++11 which simply calls the new version of GCC with -std=gnu++11 and passes a flag to the linker telling it to set the path to the 4.8 libs in the executable:

$HOME/gcc/4.8/bin/g++ -Wl,-rpath,$HOME/gcc/4.8/lib64 -std=gnu++11 -Wall -Wextra -g "$@"
查看更多
聊天终结者
6楼-- · 2020-02-02 18:15

Have you tried chroot to install a newer Debian flavor?

查看更多
登录 后发表回答