banner



How To Install Gcc On Windows

Several mod C++ features are currently missing from Visual Studio Express, and from the system GCC compiler provided with many of today'southward Linux distributions. Generic lambdas – also known as polymorphic lambdas – are one such feature. This feature is, however, available in the latest versions of GCC and Clang.

The post-obit guide will help you install the latest GCC on Windows, and then you can experiment with generic lambdas and other cutting-edge C++ features. Y'all'll need to compile GCC from sources, but that's not a problem. Depending on the speed of your machine, you can have the latest GCC up and running in every bit little every bit 15 minutes.

The steps are:

  1. Install Cygwin, which gives us a Unix-like environment running on Windows.
  2. Install a set of Cygwin packages required for building GCC.
  3. From within Cygwin, download the GCC source code, build and install it.
  4. Examination the new GCC compiler in C++14 mode using the -std=c++14 pick.

[Update: As a commenter points out, you can also install native GCC compilers from the MinGW-w64 project without needing Cygwin.]

ane. Install Cygwin

First, download and run either the 32- or 64-fleck version of the Cygwin installer, depending on your version of Windows. Cygwin's setup wizard volition walk you through a serial of steps. If your machine is located behind a proxy server, make certain to cheque "Utilise Internet Explorer Proxy Settings" when you go to the "Select Your Net Connection" step.

When y'all reach the "Select Packages" step (shown beneath), don't bother selecting any packages nonetheless. Only get alee and click Next. We'll add additional packages from the command line later.

After the Cygwin installer completes, it's very important to keep the installer around. The installer is an executable named either setup-x86.exe or setup-x86_64.exe, and y'all'll need it to add or remove Cygwin packages in the time to come. I suggest moving the installer to the aforementioned folder where you installed Cygwin itself; typically C:\cygwin or C:\cygwin64.

If you already have Cygwin installed, it's a good idea to re-run the installer to brand sure information technology has the latest available packages. Alternatively, you can install a new instance of Cygwin in a different folder.

2. Install Required Cygwin Packages

Next, you'll need to add several packages to Cygwin. Yous can add them all in one fell swoop. Simply open a Command Prompt (in Windows), navigate to the folder where the Cygwin installer is located, and run the following control:

          C:\cygwin64>setup-x86_64.exe -q -P wget -P gcc-thousand++ -P brand -P diffutils -P libmpfr-devel -P libgmp-devel -P libmpc-devel                  

A window volition popular upwardly and download all the required packages along with their dependencies.

At this indicate, yous now take a working GCC compiler on your organization. It's not the latest version of GCC; it's any version the Cygwin maintainers chose as their organisation compiler. At the fourth dimension of writing, that's GCC four.8.3. To get a more than recent version of GCC, you'll have to compile information technology yourself, using the GCC compiler you already have.

3. Download, Build and Install the Latest GCC

Open a Cygwin terminal, either from the Start bill of fare or by running Cygwin.bat from the Cygwin installation folder.

If your machine is located behind a proxy server, you must run the following command from the Cygwin terminal before proceeding – otherwise, wget won't work. This step is not needed if your machine is directly connected to the Internet.

          $ export http_proxy=$HTTP_PROXY https_proxy=$HTTP_PROXY ftp_proxy=$HTTP_PROXY                  

To download and extract the latest GCC source code, enter the post-obit commands in the Cygwin final. If you're following this guide at a later date, there will surely be a more than recent version of GCC bachelor. I used four.9.2, only you lot can use any version you like. Proceed in mind, though, that it'south e'er all-time to have the latest Cygwin packages installed when building the latest GCC. Exist patient with the tar command; it takes several minutes.

          $ wget http://ftpmirror.gnu.org/gcc/gcc-4.9.ii/gcc-four.9.2.tar.gz $ tar xf gcc-4.9.two.tar.gz                  

That will create a subdirectory named gcc-4.9.2. Next, we'll configure our GCC build. As the GCC documentation recommends, it's best to configure and build GCC in another directory outside gcc-4.9.2, so that'southward what we'll practice.

          $ mkdir build-gcc $ cd build-gcc $ ../gcc-4.9.two/configure --programme-suffix=-4.9.ii --enable-languages=c,c++ --disable-bootstrap --disable-shared                  

Hither's a description of the command-line options passed to configure:

  • The --programme-suffix=-iv.ix.2 option ways that one time our new GCC is installed, we'll run it equally g++-four.ix.2. This will make it easier for the new GCC compiler to coexist alongside the system GCC compiler provided by Cygwin.

  • The --enable-languages=c,c++ option means that only the C and C++ compilers volition be congenital. Compilers for other languages, such as Fortran, Java and Go, will be excluded. This will salve compile time.

  • The --disable-bootstrap selection means that we only want to build the new compiler one time. If nosotros don't specify --disable-bootstrap, the new compiler volition exist congenital three times, for testing and performance reasons. Withal, the system GCC compiler (four.8.3) provided by Cygwin is pretty recent, then --disable-bootstrap is expert enough for our purposes. This will relieve a significant amount of compile time.

  • The --disable-shared option ways that nosotros don't want to build the new standard C++ runtime library as a DLL that'south shared with other C++ applications on the organization. It'due south totally possible to make C++ executables work with such DLLs, just it takes intendance not to introduce conflicts with C++ executables created by older or newer versions of GCC. That's something distribution maintainers need to worry about; not us. Allow's but avoid the additional headache.

  • By default, the new version of GCC will be installed to /usr/local in Cygwin's virtual filesystem. This will make information technology easier to launch the new GCC, since /usr/local/bin is already listed in Cygwin'due south PATH environs variable. Nevertheless, if you lot're using an existing Cygwin installation, it might evidence difficult to uninstall GCC from /usr/local later on (if you then choose), since that directory tends to contain files from several different packages. If y'all adopt to install the new GCC to a different directory, add the choice --prefix=/path/to/directory to the above configure control.

We're not going to build a new Binutils, which GCC relies on, because the existing Binutils provided past Cygwin is already quite contempo. We're also skipping a couple of packages, namely ISL and CLooG, which ways that the new compiler won't be able to use any of the Graphite loop optimizations.

Next, we'll really build the new GCC compiler suite, including C, C++ and the standard C++ library. This is the longest step.

          $ brand -j4                  

The -j4 option lets the build process spawn up to four child processes in parallel. If your machine'southward CPU has at to the lowest degree four hardware threads, this selection makes the build procedure run significantly faster. The main downside is that it jumbles the output messages generated during the build procedure. If your CPU has even more hardware threads, you tin specify a higher number with -j. For comparison, I tried various numbers on a Xeon-based machine having 12 hardware threads, and got the following build times:

Be warned: I encountered a segmentation fault the showtime fourth dimension I ran with -j4. Bad luck on my part. If that happens to you, running the aforementioned command a second fourth dimension should permit the build process to stop successfully. Besides, when specifying higher numbers with -j, there are ofttimes strange error messages at the cease of the build process involving "jobserver tokens", but they're harmless.

Once that'south finished, install the new compiler:

          $ make install $ cd ..                  

This installs several executables to /usr/local/bin; it installs the standard C++ library's include files to /usr/local/include/c++/4.9.2; and information technology installs the static standard C++ library to /usr/local/lib, among other things. Interestingly, it does non install a new standard C library! The new compiler will continue to use the existing system C library that came with Cygwin.

If, later, yous make up one's mind to uninstall the new GCC compiler, you have several options:

  • If you installed GCC to a directory other than /usr/local, and that directory contains no other files, you tin simply delete that directory.
  • If you installed GCC to /usr/local, and at that place are files from other packages mixed into the same directory tree, yous tin run the list_modifications.py script from this post to determine which files are prophylactic to delete from /usr/local.
  • You can simply uninstall Cygwin itself, by deleting the C:\cygwin64 binder in Windows, forth with its associated Offset menu entry.

4. Test the New Compiler

All right, let's compile some code that uses generic lambdas! Generic lambdas are role of the C++14 standard. They allow y'all laissez passer arguments to lambda functions as machine (or any templated type), like the one highlighted below. Create a file named test.cpp with the following contents:

#include <iostream>  int main() {     auto lambda = [](automobile            10){ render 10; };     std::cout << lambda("Hi generic lambda!\due north");     return 0; }          

You tin add together files to your home directory in Cygwin using any Windows-based text editor; simply save them to the folder C:\cygwin64\abode\Jeff (or similar) in Windows.

Showtime, permit's encounter what happens when we attempt to compile information technology using the system GCC compiler provided by Cygwin:

          $ g++ --version $ yard++ -std=c++1y exam.cpp                  

If the organization compiler version is less than 4.ix, compilation will fail:

At present, let'south try information technology once more using our freshly built GCC compiler. The new compiler is already configured to locate its include files in /usr/local/include/c++/iv.9.2 and its static libraries in /usr/local/lib. All we need to do is run information technology:

          $ g++-4.9.2 -std=c++14 examination.cpp $ ./a.exe                  

It works!

How To Install Gcc On Windows,

Source: https://preshing.com/20141108/how-to-install-the-latest-gcc-on-windows

Posted by: feltonbreserand.blogspot.com

0 Response to "How To Install Gcc On Windows"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel