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
Related
This question already has answers here:
Eclipse CDT does not find either Cygwin or MinGW toolchain
(5 answers)
How to configure Eclipse CDT for cmake?
(7 answers)
Closed 1 year ago.
everyone! I am learning to use eclipse CDT to develop codes in c++ recently. I have installed eclipse on my ubuntu 16.04. When I started eclipse in terminal, I got the output:
(base) ...#...-VirtualBox:~$ eclipse
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Unable to find full path for "gcc"
Unable to find full path for "g++"
Unable to find full path for "gcc"
Unable to find full path for "g++"
The eclipse application still can work though. Then when I tried to build my hello.world.cpp in eclipse,
it reports:
Configuring in: /home/.../eclipse-workspace/test01/build/default
cmake -G Unix Makefiles -DCMAKE_EXPORT_COMPILE_COMMANDS=ON /home/.../eclipse-workspace/test01
Error: build command 'cmake' not foundFailure running cmake:
I have installed gcc/g++ too. Below are my output in terminal to find gcc/g++ dir:
(base) ...#...-VirtualBox:~$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 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.
(base) ...#...-VirtualBox:~$ g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.12) 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.
(base) ...#...-VirtualBox:~$ which gcc
/usr/bin/gcc
(base) ...#...-VirtualBox:~$ which g++
/usr/bin/g++
I only have limited knowledge about compiling/configuration (and I am new to eclipse), so maybe my question is a little stupid. I have searched on the internet but those information cannot solve my problem.
Can anyone help me? Thanks in advance.
adding:
I think my question is not the same as those which "already have answers". I checked them and found that they are mostly about windows system. I doubt if they would also work in ubuntu and I have to say I did not find answers to my questions (I tried some methods and failed ). Still hoping to get help.
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.
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.
In file included from /usr/include/c++/4.8.2/locale:41:0,
from /usr/include/c++/4.8.2/iomanip:43,
from [...omitted by myself as it is irrelevant]
/usr/include/c++/4.8.2/bits/locale_facets_nonio.h:59:39: error: ‘locale’ has not been declared
struct __timepunct_cache : public locale::facet
Above is the first error in my build log.
I didn't try to compile glibc/gcc myself, and I installed them via yum.
One fishy thing I found is:
$ ll /usr/include/c++/
total 4
drwxr-xr-x. 12 root root 4096 Dec 17 14:16 4.8.2
lrwxrwxrwx 1 root root 5 Dec 17 14:16 4.8.5 -> 4.8.2
$
And yum showed only 1 version of gcc:
$ yum info gcc-c++
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.uhost.hk
* epel: mirrors.hustunique.com
* extras: centos.uhost.hk
* updates: centos.uhost.hk
Installed Packages
Name : gcc-c++
Arch : x86_64
Version : 4.8.5
Release : 4.el7
Size : 16 M
Repo : installed
From repo : base
Summary : C++ support for GCC
URL : http://gcc.gnu.org
License : GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD
Description : This package adds C++ support to the GNU Compiler Collection.
: It includes support for most of the current C++ specification,
: including templates and exception handling.
Any idea how to verify the headers in /usr/include/c++/4.8.2 is indeed from 4.8.5 package?
Thanks in advance.
P.S. I think probably glibc is irrelevant but here is the info:
$ ldd --version
ldd (GNU libc) 2.17
Copyright (C) 2012 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.
Written by Roland McGrath and Ulrich Drepper.
The symlink to the 4.8.2 directory is nothing to worry about, it's normal for the libstdc++ headers on Red Hat Enterprise Linux (and therefore CentOS) to be arranged like that.
gcc --version will tell you the version of the gcc executable in your path.
rpm -q libstdc++-devel will tell you the version of the package that owns the C++ standard library headers.
rpm -ql libstdc++-devel will list the files installed by that package, which will include the files under /usr/include/c++/4.8.2
rpm --verify libstdc++-devel will check that you haven't messed up the C++ headers by replacing them with something else.
The error is more concerning, that implies you have messed something up. My guess would be it's in the from [...omitted by myself as it is irrelevant] part, which may actually be very relevant. std::locale should be declared in <bits/locale_classes.h> which is included before <bits/locale_facets_nonio.h>, so if it wasn't declared my guess is that you have some header that defines _LOCALE_CLASSES_H and prevents the standard library header from being read. Do not define include guards that start with underscores, they are reserved names.
I am not quite sure but below is more information
Stackoverflow: version of libc
$ /lib/x86_64-linux-gnu/libc.so.6
GNU C Library (Ubuntu EGLIBC 2.19-0ubuntu6) stable release version 2.19, by Roland McGrath et al.
Copyright (C) 2014 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.
Compiled by GNU CC version 4.8.2.
Compiled on a Linux 3.13.9 system on 2014-04-12.
Available extensions:
crypt add-on version 2.1 by Michael Glad and others
GNU Libidn by Simon Josefsson
Native POSIX Threads Library by Ulrich Drepper et al
BIND-8.2.3-T5B
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<https://bugs.launchpad.net/ubuntu/+source/eglibc/+bugs>.
mandar#ubuntu:~/Desktop$
Since you are using Linux you can try
ldd --version
I recently installed MinGW and learnt how to use Make. But I get an error whenever I try to compile a CPP source file using make. Below is the output:
MAKE Version 3.6 Copyright (c) 1991 Borland International
Available memory 33397872 bytes
mingw32-g++ main.cpp --std=c++11 -o program
Bad command or file name
The main.cpp is a very simple "Hello World" type program. The command works when I use it in the Command Prompt directly.
I am running Windows 8.1 with MinGW. GCC version 4.8
I think you would like to learn GNU make, not Borland one from 1991.
Make sure you installed GNU make package in Cygwin. Check that it is present by typing in the bash command line:
$ type -a make
It should respond with something like:
/usr/bin/make
/bin/make
And then:
$ make --version
Which should respond with something like:
GNU Make 4.1
Built for x86_64-unknown-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
As another respondent has noted, you should not be trying to coax Borland's antique make into working with MinGW; the most appropriate option for you would be either mingw32-make, (a native windows build of GNU make suitable for use directly from a cmd.exe shell session), or install MinGW.org's MSYS, and use the make which it provides; either of these may be installed using MinGW.org's mingw-get installation manager.
Either of these options should work for you, while avoiding the bloat of Cygwin, (or the equally bloated MSYS2, which should not be confused with the MinGW.org MSYS product). Do note that, if you choose the MSYS option, you will be installing a very light-weight fork of an old, but still perfectly adequate and capable, version of Cygwin.
In closing, to clear up your evident confusion, I would also point out that the g++.exe which you find in the $MINGW32_ROOT/bin directory, and the mingw32-g++.exe to which you refer, are one and the same -- both are the MinGW compiler, and you would normally invoke it simply as g++.