Factsheet
Where to download GNU C++ compiler - Stack Overflow
c++ - What is the difference between g++ and gcc? - Stack Overflow
How can I setup the GNU/GCC compiler in the Windows environment?
GCC (GNU Compiler Collection): resources on potential improvements or new features?
Videos
https://gcc.gnu.org/gcc-15/
Some discussion on hackernews: https://news.ycombinator.com/item?id=43792248
Awhile back, there was some discussion of code like this:
char a[3] = "123";
which results in a an array of 3 chars with no terminating NUL byte, and no warning from the compiler about this (was not able to find that discussion or I would have linked it). This new version of gcc does have a warning for that. https://gcc.gnu.org/pipermail/gcc-patches/2024-June/656014.html And that warning and attempts to fix code triggering it have caused a little bit of drama on the linux kernel mailing list: https://news.ycombinator.com/item?id=43790855
Getting everything you need on Debian/Ubuntu is very easy:
sudo apt-get install build-essential
What about using GCC ?
Quoting it's homepage :
The GNU Compiler Collection includes front ends for C, C++, Objective-C, Fortran, Java, and Ada, as well as libraries for these languages (libstdc++, libgcj,...).
It will definitly work on Ubuntu ; it's even provided through the package system (sorry, my system is in french) :
$ apt-cache show g++
Package: g++
...
Description-fr: Compilateur C++ du projet GNU
Le compilateur C++ du projet GNU. Un compilateur C++ relativement portable
et capable de bonnes optimisations.
(which translates to Description: The GNU C++ compiler. This is the GNU C++ compiler, a fairly portable optimizing compiler for C++. in English)
For informations about Windows support, you can have a look at : http://gcc.gnu.org/install/specific.html#windows
Something like MinGW or Cygwin will probably do :-)
Quoting MinGW's homepage :
MinGW, a contraction of "Minimalist GNU for Windows", is a port of the GNU Compiler Collection (GCC), and GNU Binutils, for use in the development of native Microsoft Windows applications.
For netbeans, I can't tell : I don't use it -- not for C++, at least...
gcc and g++ are compiler-drivers of the GNU Compiler Collection (which was once upon a time just the GNU C Compiler).
Even though they automatically determine which backends (cc1 cc1plus ...) to call depending on the file-type, unless overridden with -x language, they have some differences.
The probably most important difference in their defaults is which libraries they link against automatically.
According to GCC's online documentation link options and how g++ is invoked, g++ is roughly equivalent to gcc -xc++ -lstdc++ -shared-libgcc (the 1st is a compiler option, the 2nd two are linker options). This can be checked by running both with the -v option (it displays the backend toolchain commands being run).
By default (and unlike gcc), g++ also adds linker option -lm -- to link against libm which contains implementations for math.h.
GCC: GNU Compiler Collection
- Referrers to all the different languages that are supported by the GNU compiler.
gcc: GNU C Compiler
g++: GNU C++ Compiler
The main differences:
gccwill compile:*.c\*.cppfiles as C and C++ respectively.g++will compile:*.c\*.cppfiles but they will all be treated as C++ files.- Also if you use
g++to link the object files it automatically links in the std C++ libraries (gccdoes not do this). gcccompiling C files has fewer predefined macros.gcccompiling*.cppandg++compiling*.c\*.cppfiles has a few extra macros.
Extra Macros when compiling *.cpp files:
#define __GXX_WEAK__ 1
#define __cplusplus 1
#define __DEPRECATED 1
#define __GNUG__ 4
#define __EXCEPTIONS 1
#define __private_extern__ extern
I apologize for the long post in advanced-- I'm just trying to describe what I've already tried as best as possible in order to better troubleshoot the issue.
I am in an introductory C++ class and we have been using the school computers with all the environments already pre-configured for us. The teacher told us that we can simply download CodeBlocks or XCode for Win/macOS and use the GNU/GCC compiler without any problems. He also stated multiple times that for our curriculum, we would require this compiler specifically instead of something like MSVC, since it better follows traditional C++ standards and allows teachers and students to build any source code on multiple machines.
I installed Codeblocks a little while ago and I'm trying to get my source code running on my home computer now. To my surprise, Codeblocks could not automatically find the compiler on my system after following the default installation (full features). When doing a custom Windows Explorer search for the compiler executable on my entire hard drive, it could not find any trace of the file located on my computer either. Our teacher said that this compiler should be included in the Codeblocks installation, but it looks to me as though didn't install it whatsoever. I also checked to ensure I was downloading the latest version, re-ran the installation as admin, but there was still no trace of the compiler anywhere to be found.
After doing some investigating online, I learned that the GNU compiler is actually not a Windows compiler at all but was mainly developed for Unix based systems first. The compiler that Codeblocks expects is actually "mingw" which is apparently a port of the free GCC compiler from these other platforms.
I found the "mingw installation manager" binary package online, installed it on my system, then proceeded to download and install all the packages under the mingw repositories 'basic setup'. After applying the changes, it installed mingw to a root folder on my C:\\ drive where Codeblocks first expected it, which then allowed me to build/run the basic example script "Hello World" within the IDE. All seemed well now, except there were still some other problems happening...
While trying to build my script I'd previously been working on, one of the namespaces from the <thread> library threw a compiler error. This error did not show up while working on the school's computers, which leads me to believe that I might be missing some additional packages of some sort. If this is the case, then this is going to cause a lot of trouble down the road when trying to build source code that could be using correct syntax but missing some other resource.
To ensure that I am not just crazy, please see this small snip-it to verify the source code:
#include <iostream> #include <thread> #include <string> #include <chrono> using namespace std; using namespace std::chrono; using namespace std::this_thread; // error: compiler complains that "this_thread" is not a namespace-name
In my global compiler settings within Codeblocks, I have also checked the following box:
Have g++ follow the C++14 ISO C++ language standard [-std=c++14]
Why is the compiler not finding the std::this_thread; namespace? Am I missing a resource? How can I setup up my computer with everything I need using the mingw GNU/GCC compiler?
PS: I am trying to use std::this_thread::sleep_for() from the <thread> library in order pause the program and allow the user to see a displayed message before it is cleared from the standard output in the console.