Downgrade gcc/g++ in Ubuntu? - c++

I am trying to downgrade gcc/g++ to 4.8.1. I tried two options, both with problems.
use sudo apt install gcc-4.8 g++-4.8. This option will install 4.8.5 etc. I wonder if there is any way to specify 4.8.1. sudo apt install gcc-4.8.1 g++-4.8.1 does not work as it will complain that "unable to locate package gcc-4.8.1".
Download "gcc-4.8.1" and follow the official steps ("configure, make, make install") but it fails at the make step with errors "CXXABI_1.3.8" not found.
I found another solution but I am not sure whether it is desirable (" install gcc-4.8.1 from source code on Ubuntu-16.04").
How do I downgrade gcc/g++ to 4.8.1 in Ubuntu?
Many thanks.

How do I downgrade gcc/g++ to 4.8.1 in Ubuntu?
I think you want look into the command "update-alternatives" (instead of 'downgrade').
To learn some more browse "https://askubuntu.com/questions/529687/how-to-use-update-alternatives-to-manage-multiple-installed-version-of-the-sam"
The update-alternatives works by changing what the command g++ points at. Currently on my system, g++ points to g++-6.
I have sometimes experienced an install that simply does not work. My recent g++ v6.2 install is broken, I don't know why.
But because my ubuntu is out of date, I plan to upgrade to the latest ubuntu. I might as well wait to install the latest compiler.
In the mean time I have 6.2.0, which does not 'work' (cause unknown). g++ points to this:
~$ g++ --version
g++ (GCC) 6.2.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Since I seldom remove (un-install) the previous version in use, it turns out that with a simple search to identify what is available, I can access an older compiler using a suffix. For example
~$ g++-5 --version
g++-5 (Ubuntu 5.2.1-23ubuntu1~15.10) 5.2.1 20151028
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
So, I continue more or less the same as before the failed 6.2.0 install.
For you, I think this means that you can use your package manager to install your desired earlier compiler, but remember to search for it in case it already exists on your system. Then use update-alternatives to make it the default, or just learn the new command name to invoke, i.e. g++-5, and continue developing with both commands easily available.

Related

gcc - suffix suppression during cross-compilation Windows PE on Ubuntu

System info:
Distributor ID: Ubuntu
Description: Ubuntu 20.04.4 LTS
Release: 20.04
Codename: focal
Using x86_64-w64-mingw32-gcc:
x86_64-w64-mingw32-gcc --version
x86_64-w64-mingw32-gcc (GCC) 9.3-win32 20200320
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
For a project we are using mingw to cross-compile Windows PE files on Ubuntu. During the cross-compilation we are making modifications to the files. During cross-compilation, the following code is used in the Python script:
x86_64-w64-mingw32-gcc {path} -o {outfile} -static
When the process starts we have a file, somefile (no extension is used), but after going through the cross-compilation the newly compiled file is called somefile.exe.
On an older Ubuntu system, I believe it was 17.##, my apologies but the box is offline and I don't remember the exact versioning, we could run the script and the filename would be preserved, no .exe appended to the filename.
The addition of .exe to the filename is causing some issues with my workflow, and I'm hoping there's a way around this outside of cloning the old Ubuntu system to newer hardware. This may work, but logistically it's not ideal.
We're able to make some modifications by bash during the process, but this is creating unwanted artifacts. And we'd like to keep our system processes streamlined.
An older post, gcc - how to force to not add .exe suffix, suggests adding a . to the end of -o {outfile}, removing the suffix leaving a .. While a great idea, this still has issues with our workflow in that the filename, a SHA256 hash, is used and no extension is looked for (the . still causes issues).
If anyone has any insight on how this may be remedied, perhaps modifying the main.c file that is referenced during compilation, it's greatly appreciated. I can provide more information if necessary.
Also, my apologies if the post is missing any mission-critical information, I'm new to posting here.

GCC or Clang Version on Amazon AWS Cloud 9?

When using Cloud 9 (now owned by Amazon and run as part of their AWS service) as an onlinet IDE for C and C++, and other compiled languages, it seems to create a virtual machine that uses version 4.8.5 of GCC. How do I use a more modern version of GCC, in order to utilize the C11 standard (and C18 revisions) and C++11 (and C++17 revisions) and to better utilize the more comprehensible and more friendly compiler error messages of more recent GCC, and Clang, versions.
How do I "request" or install a more modern version of GCC or possibly use a recent version of Clang as the compiler from within the Cloud 9 AWS instance/virtual machine?
The following command got my Cloud 9 IDE up to gcc version 7.2.1
sudo yum -y groupinstall "Development Tools"
gcc --version
gcc (GCC) 7.2.1 20170915 (Red Hat 7.2.1-2)
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

How to update g++ compiler on OSX

I tried using this tutorial to download the newest version of g++, and I changed the version number from 4.7 to the newest (which is believe is) 8.1. But I get the following errors
Error: No available formula with the name "gcc81"
==> Searching for a previously deleted formula (in the last month)...
Warning: homebrew/core is shallow clone. To get complete history run:
git -C "$(brew --repo homebrew/core)" fetch --unshallow
Error: No previously deleted formula found.
==> Searching for similarly named formulae...
==> Searching local taps...
Error: No similarly named formulae found.
==> Searching taps...
==> Searching taps on GitHub...
Error: No formulae found in taps.
Does anyone know how to update my g++ version? This is what I get when I try to find out my current version.
g++ --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.1.0 (clang-902.0.39.1)
Target: x86_64-apple-darwin17.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Sorry Im such a noob, I really trying to learn here.
I know this post is a little old but I can shine some light regarding how to accomplish this.
Firstly, to install gcc/g++ using Homebrew, you should use the following command as mentioned in the comments above: brew install gcc
After doing this, Homebrew should place the installed binaries/symlinks in the correct folders.
To correctly setup the gcc/g++ command on mac to use the version you just downloaded, I do this by not changing the symlinks gcc/g++ but instead creating aliases for both gcc and g++ within my shell environment.
alias gcc='gcc-10'
alias g++='g++-10'
gcc-10 and g++-10 were downloaded using Homebrew. When doing this, Homebrew places gcc-10 and g++-10 in /usr/local/bin (which is on the path) and it allows you to create an alias for the regular gcc/g++ commands which point to the versions installed by Homebrew.
After doing this, running the command g++ --version should give you the following:
g++-10 (Homebrew GCC 10.2.0) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
You may need to restart your terminal or run source ~/.bashrc depending on the type of shell you're using.

Checking the C++ version on my laptop

I am currently in a CS class where we use C++, and I run Linux on my laptop. So the problem is that I think I don't have the most up to date version of C++. I've read online for several commands to get the version and this is my result. Also my Linux version is 16.04, and I am compiling in my terminal
tom#TBT-XPS-13-9360:~/Documents/Subjects/CS/OOP$ g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There
is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
I don' know what part of this is my actual version of C++. If my version is not the most up to date, can someone please give me DETAILED instructions on how to do it. Still getting my Linux legs.
C++ version (Or usually called c++ standard) is different than compiler version.
g++ is your compiler, and your current version is g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
You can use different command to compile your program using different C++ version.
g++ -std=c++11 yourFile .....
g++ -std=c++14 yourFile .....
As mentioned in the comments, this version of compiler may not support c++17 features yet
Use this command in terminal (for linux only)
cpp --version

Using GCC Through Git Bash

I have Git for Windows 2.10.2 and the latest version of MSYS2 installed on my Windows 7 machine. I had been using an older version of MinGW to compile c++ code. I would use notepad++ to write/edit the files and compile and run them through Git Bash using gcc console commands. I love being able to go to my file directory, right click, and select the "Git Bash Here" option to open the console and do whatever I needed.
After uninstalling MinGW, I installed MSYS2 and downloaded some of their packages using the package manager, Pacman, that comes with MSYS2. I also updated my PATH variable. I went to test everything out with Git Bash by typing the command:
gcc --version
and I've been getting this error
OWNER#Seth MINGW64 /c
$ gcc --version
2 [main] gcc (5284) C:\msys64\usr\bin\gcc.exe: *** fatal error - cygheap base mismatch detected - 0x1802FF408/0x1802FE408.
This problem is probably due to using incompatible versions of the cygwin DLL.
Search for cygwin1.dll using the Windows Start->Find/Search facility
and delete all but the most recent version. The most recent version *should*
reside in x:\cygwin\bin, where 'x' is the drive on which you have
installed the cygwin distribution. Rebooting is also suggested if you
are unable to find another cygwin DLL.
Segmentation fault
OWNER#Seth MINGW64 /c
$
I've never used Cygwin and therefore have never installed it on this computer. I've spent the last three days searching online for solutions to this. I've uninstalled and reinstalled Git and MSYS2. I put the git-bash.exe in my c:\msys64\ directory and ran the same command from there and got:
OWNER#Seth MINGW64 ~
$ gcc --version
gcc.exe (Rev2, Built by MSYS2 project) 6.2.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
OWNER#Seth MINGW64 ~
$
but that doesn't seem to me to be a very elegant solution. It does work though, I can cd to the folder containing my code and compile and run them.
Another thing I tried was to go into the registry and change where the "Git Bash Here" option looks for git-bash.exe. I changed it from:
"C:\program files\Git\git-bash.exe" "--cd=%v."
to
"C:\msys64\git-bash.exe" "--cd=%v."
and now right clicking and selecting "Git Bash Here" and running the command:
gcc --version
results in:
OWNER#Seth MINGW64 ~
$ gcc --version
gcc.exe (Rev2, Built by MSYS2 project) 6.2.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
OWNER#Seth MINGW64 ~
$
and once again I can cd to the folder with my code and compile and run them.
The problem now is that before when Git Bash would open, it would be looking in the directory where I had right clicked. But now I have to cd to where ever I'm needing to go.
Is there a better way to get MSYS2 and Git working together? Am I making this way more difficult than it should be? Or is there a better way and I'm just stumbling around in the dark?

Categories