0

Newbie in Linux. I have a linux developer machine at my organization which has a compiler which is old.

gcc --version gives the following 
gcc (GCC) 4.4.7 ... 

I have a small piece of code that came from a different machine that uses a lot of C++11 features. Obviously, compiling it in my current linux box gives a lot of errors.

Compiler upgrade in the linux box is completely out of question due to legacy issues.

So I have two options,

  1. rewrite everything to suit C++98 / 03 standards, or
  2. which is a question

Can I have an updated version the gcc compiler copied within my local directory and use it to compile my code within that folder ?

It shouldn't affect the compilation of my Organizational code outside this folder which uses the older gcc compiler that comes with Linux.

I haven't researched anything much unless this is possible. Basically I wouldn't want to touch any of my global settings lest it would break my project.

But I would like to have a folder within my local path and work with an updated compiler to compile and test my code from another machine.

jww
  • 97,681
  • 90
  • 411
  • 885
  • 2
    Yes, you can install GCC anywhere you want. The installation instructions should include documentation for how to install it in a non-default location. – Barmar Jul 31 '19 at 05:35
  • You can install clang with no brainer – Oblivion Jul 31 '19 at 05:35
  • 1
    "Obviously" to whom? 4.4.7 is old, but not that old. It came out in 2012. C++11 support was mostly in place by that time. Perhaps you are not enabling it. – n. m. could be an AI Jul 31 '19 at 05:45
  • @n.m. 2012 is 7 years ago. In 2012, 7 years is how old YouTube was. In 2012, Stack Overflow was 4 years old and node.js was 3. – user253751 Jul 31 '19 at 07:38
  • 1
    @n.m. According to [this](https://gcc.gnu.org/gcc-4.4/cxx0x_status.html), I doubt 4.4 is going to compile anything written in actual C++11. – Daniel Kamil Kozar Jul 31 '19 at 07:46
  • Did you try it with `-std=c++0x`? https://gcc.gnu.org/gcc-4.4/cxx0x_status.html and https://stackoverflow.com/a/23523710/283561 state that you should have at least partial C++11 support with 4.4.7 – Simon Jul 31 '19 at 07:58
  • I have tried the various flags for std11, unfortunately, version 4.4.7 is not fully compliant with 11 standards,It does support many of the 11 features tho. My own piece of code will fail. – Confused Programmer Jul 31 '19 at 11:06

1 Answers1

0

Yes.

This is done all the time for ARM cross-compilation for SBCs like Raspberry Pi and Android devices. A specific GCC based toolchain like Lenaro is unpacked in a different folder such as /opt to cross compile ARM software on X86 machines.

You can manually run the desired binary with full path, or source a script to temporarily set environment variables to use build automation tools such as make.

I could not find an easy to use package for you with a quick search, but you can either build one following instructions here or manually download a package from updated distro like Ubuntu, and unpack it by hand in to any directory you want.

Lev M.
  • 6,088
  • 1
  • 10
  • 23
  • Thank you for the solution. New to linux , Couldn't find a step by step guide to set up my own compiler version but definitely would read thru the link. – Confused Programmer Jul 31 '19 at 12:24