12

My Debian 7 armel embedded system currently has g++ 4.6, and I'd like to upgrade to g++ 4.9 to use new C++11 features. How do I do that?

My current sources.list contents is:


    deb http://security.debian.org/ wheezy/updates main
    deb-src http://security.debian.org/ wheezy/updates main
    deb http://ftp.us.debian.org/debian wheezy main non-free
    deb-src http://ftp.us.debian.org/debian wheezy main non-free

A simple apt-get install of the package does not work:


    root@arm:~#  apt-get install g++-4.9
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    E: Unable to locate package g++-4.9
    E: Couldn't find any package by regex 'g++-4.9'

manlio
  • 18,345
  • 14
  • 76
  • 126
user43995
  • 597
  • 2
  • 8
  • 21
  • `sudo apt-get install g++-4.9`? – The Paramagnetic Croissant Aug 05 '14 at 20:05
  • You may need `jessie` for that. – Marc Glisse Aug 05 '14 at 20:18
  • 1
    A simple apt-get install does not work, alas. – user43995 Aug 05 '14 at 21:32
  • 2
    You might want to try to add the "testing" repository to your sources.list: `deb http://http.us.debian.org/debian/ testing contrib main` (you could add the `non-free` subbranch as well, I'm pretty sure this isn't needed for gcc though). –  Aug 05 '14 at 21:37
  • 1
    Look at the [Debian package search](https://packages.debian.org/search?keywords=gcc-4.9), there is no gcc-4.9 for *wheezy*. You can get [crosstool-ng](http://crosstool-ng.org/) and build your own compiler. Otherwise, someone needs to point you to a '.deb' for 4.9; it may exist some time in the future. – artless noise Aug 05 '14 at 21:42
  • Yes I agree and I think that crosstool-ng is only the right solution for embedded system. – Mazeryt Sep 12 '14 at 13:28

4 Answers4

17

Another workaround could be to install the g++ 4.9 packages from "Jessie", according to this blog post. Briefly, you would have to tell APT to use the Jessie repos while you are installing the new G++. First bring the current Wheezy up-to-date:

sudo apt-get update
sudo apt-get upgrade

Then do a backup :-) and edit /etc/apt/sources.list so that you replace the string "wheezy" with "jessie":

sudo cp /etc/apt/sources.list /etc/apt/sources.list.WHEEZY
sudo vi /etc/apt/sources.list

Now update the package list and install the 4.9 version of GCC/G++:

sudo apt-get update
sudo apt-get install gcc-4.9 g++-4.9

After this revert to the "original" package list:

sudo cp /etc/apt/sources.list.WHEEZY /etc/apt/sources.list
sudo apt-get update

This leaves the original GCC,G++ in place. If you wish to compile with the 4.9 version, then either set the CC and CXX env vars accordingly or invoke the compilers as gcc-4.9 or g++-4.9 explicitly.

András Aszódi
  • 8,948
  • 5
  • 48
  • 51
  • 5
    Three people have indicated that this was a useful post but nobody claimed it works. I followed the steps above and it worked. Thank you for this. – Sting Jan 22 '16 at 17:26
  • 1
    I will also add that it works, and was essential to get Page Speed Module running on Debian 7 wheezy. Thanks! – petergus Apr 04 '18 at 06:46
  • 1
    This also worked for me to get Stretch's `gcc-6.3` on Wheezy. I did the above with the following line in my `sources.list` file: `deb http://deb.debian.org/debian stretch main non-free contrib`. Thank you for your answer! – peachykeen May 05 '20 at 14:10
5

Probably-required: packaging-dev, ubuntu-dev-tools

Set up pbuilder

(this lets you build a package in a chroot without polluting your system with build-dependency packages)

sudo pbuilder create

if you want to build for a specific distribution, (pbuilder uses the build system release in a chroot) you can use pbuilder-dist [precise/oneric/trusy/etc...] create

Get debian source

pull-debian-source gcc-4.9 [4.9.0-6] 

specific debian revision is optional, but can be useful if you want to pull experimental/unstable/testing/stable revisions you can also pull from specific ubuntu distros by adding them to sources.list as a deb-src and using sudo apt-get src

Build Package

sudo pbuilder build gcc-4.9_4.9.0-6.dsc

In the files downloaded there is a .dsc file, for the most recent gcc it is gcc-4.9_4.9.0-6.dsc which is a package descriptor file. .orig.tar.[gz/xz] is the source tarball.

Create local Apt-repository

mkdir /convenient/place/for/repo
cp /var/cache/pbuilder/result/* /path/to/repo
cd /path/to/repo
apt-ftp archive packages . > Packages
sudo echo "deb [trusted=yes] file:/local/repo/Packages ./" > /etc/apt/sources.list.d/gcc-repo.list`

Note you can also do this step with .debs downloaded from anywhere (skip step 1-3)

Install

apt-get update; apt-get install gcc-4.9 g++-4.9
Community
  • 1
  • 1
  • Wont this just build the package in a new environment from a later release? Seems no different to downloading from jessie. – jgmjgm Sep 14 '15 at 13:15
  • These instructions worked fine for me, but just a warning for anyone who wants to follow these steps: building gcc/g++ takes a long time. The downloads take a while, and the compile itself takes a while. So don't do this if you're in a hurry. – Chris Eberle Jun 21 '16 at 21:03
1

Instead of using the jessie packages, it would be better to check to see if it's been back-ported to wheezy. Add this to your /etc/apt/sources.list:

deb http://http.debian.net/debian wheezy-backports main

and do an apt-get update and see if you can install it then.

DrHyde
  • 1,546
  • 1
  • 14
  • 14
0

There is a gcc-4.9-backport now.

sudo apt-get update && sudo apt-get install gcc-4.9-backport
xqliang
  • 357
  • 2
  • 4