banner



How To Install Gcc Compiler In Cygwin

Follow these steps to install g++ (the GNU C++ compiler) for Windows. There is no room for creativity here; you must follow the directions exactly.

  1. Pick the bulldoze and a folder in which you desire to install chiliad++. I'll presume that it is C:, but you tin can choose a different one. If you choose a dissimilar bulldoze or a dissimilar folder, you'll need to arrange the directions below accordingly.
  2. Download total.exe, an nearly fourteen megabyte executable, to C:\full.exe past correct-clicking on the link. Utilize Save Link Equally… or Relieve Target As… Be sure the browser saves the file equally C:\full.exe.
  3. Run the downloaded executable. This will install thou++ (and a lot of other things that you don't really demand) on your hard drive. Get to the C: drive using Windows Explorer and double-click on full.exe. Or, open a DOS command prompt window (Get-go > Programs > Command Prompt), connect to the C: drive using the cd command, and type full.
  4. Locate where the bin folder was created for the g++ installation. On my Windows machine, it was created in the post-obit path:C:\cygnus\cygwin-b20\H-i586-cygwin32\bin You at present should add together it to the PATH surround variable. Y'all do that past post-obit: Start -> Control Panel -> Organisation -> Advanced -> Environment Variables At this point you lot can see the PATH variable either in the User Variables or in the Organization Variables. Add the g++ path into the PATH variable. You add it to the end of theexisting value separated by a semicolon (';'). Make sure that you practise not lose the original value. You are just appending more to the end separated past a semicolon.
  5. Restart your computer. A Cygnus Solutions entry volition appear in your Programs menu, and an icon may appear on your desktop.Don't apply them! You will apply it using the g++ control on a DOS command prompt equally explained beneath.

You lot should now be able to run g++ from a DOS control prompt window. For example, to compile a file called C:\mine\hello.cpp, connect to the C:\mine folder and enter

          g++ -thousand hullo.cpp -o hello -lm        

You'll then exist able to run the compiled program by entering hello in the DOS command prompt window.

If you've installed Emacs equally described here, you will also be able to run grand++ from Emacs. If, when you exercise this, Emacs tries to compile with the command make -k, you made a mistake during the Emacs installation. (If you try to compile a C program, e.yard., hello.c instead of a C++ program, e.g., hello.cpp, information technology will attempt make -k. In that instance enter the compile command, gcc -k hullo.c -o hello -lm, manually. After yous try it manually once, from second time on it will do the right thing automatically.) If you want to learn how to run thou++ on emacs, see here.

If you'd similar to learn more almost where this free compiler came from, we downloaded it from an older site of http://sourceware.org/cygwin/.

If you wish to clean up a little, you may delete the file: total.exe at this point. Your g++ compiler is installed under C:\cygnus.

Several mod C++ features are currently missing from Visual Studio Limited, and from the arrangement GCC compiler provided with many of today's Linux distributions. Generic lambdas – also known every bitpolymorphic lambdas – are one such characteristic. This feature is, however, available in the latest versions of GCC and Clang.

The following guide will assist yous install the latest GCC on Windows, and so you can experiment with generic lambdas and other cut-edge C++ features. You'll demand to compile GCC from sources, merely that's non a problem. Depending on the speed of your automobile, you tin can have the latest GCC upwardly and running in as footling as15 minutes.

The steps are:

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

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

1. Install Cygwin

Start, download and run either the 32- or 64-bit version of the Cygwin installer, depending on your version of Windows. Cygwin'due south setup wizard will walk you lot through a series of steps. If your machine is located backside a proxy server, make sure to check "Apply Cyberspace Explorer Proxy Settings" when you lot get to the "Select Your Net Connection" step.

When you reach the "Select Packages" stride (shown beneath), don't carp selecting whatever packages yet. Just go ahead and click Next. We'll add additional packages from the command line later.

After the Cygwin installer completes, it's very important to go along the installer around. The installer is an executable named eithersetup-x86.exe orsetup-x86_64.exe, and yous'll demand it to add or remove Cygwin packages in the time to come. I suggest moving the installer to the same folder where you installed Cygwin itself; typicallyC:\cygwin orC:\cygwin64.

If you already have Cygwin installed, it'southward a good idea to re-run the installer to make sure it has the latest available packages. Alternatively, y'all can install a new case of Cygwin in a different folder.

two. Install Required Cygwin Packages

Next, y'all'll need to add several packages to Cygwin. You can add them all in one barbarous dive. Only open up a Command Prompt (in Windows), navigate to the folder where the Cygwin installer is located, and run the following command:

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

A window volition pop upward and download all the required packages forth with their dependencies.

At this point, y'all now have a working GCC compiler on your organization. It'due south non the latest version of GCC; it's whatever version the Cygwin maintainers chose equally their system compiler. At the time of writing, that's GCC 4.viii.iii. To get a more recent version of GCC, you'll have to compile information technology yourself, using the GCC compiler you already take.

3. Download, Build and Install the Latest GCC

Open a Cygwin terminal, either from the Start menu or by runningCygwin.bat from the Cygwin installation folder.

If your machine is located behind a proxy server, y'all must run the following control 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.

$ consign 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 terminal. If you're following this guide at a later engagement, at that place volition surely be a more recent version of GCC available. I used iv.9.ii, simply you can use any version you similar. Continue in listen, though, that information technology'due south always best to have the latest Cygwin packages installed when edifice the latest GCC. Exist patient with thetar control; it takes several minutes.

$ wget http://ftpmirror.gnu.org/gcc/gcc-4.9.2/gcc-4.9.2.tar.gz $ tar xf gcc-iv.9.2.tar.gz          

That will create a subdirectory namedgcc-4.9.2. Next, we'll configure our GCC build. Equally the GCC documentation recommends, information technology's best to configure and build GCC in some other directoryoutsidegcc-four.nine.2, so that's what nosotros'll practise.

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

Hither'southward a description of the command-line options passed toconfigure:

  • The--program-suffix=-4.9.2 selection ways that one time our new GCC is installed, we'll run information technology equally1000++-four.nine.2. This will make it easier for the new GCC compiler to coexist alongside the arrangement GCC compiler provided past Cygwin.
  • The--enable-languages=c,c++ selection means that merely the C and C++ compilers will be built. Compilers for other languages, such as Fortran, Java and Go, will be excluded. This will salve compile fourth dimension.
  • The--disable-bootstrap option means that we but desire to build the new compiler once. If we don't specify--disable-bootstrap, the new compiler volition be built three times, for testing and performance reasons. However, the system GCC compiler (four.8.3) provided past Cygwin is pretty recent, then--disable-bootstrap is good enough for our purposes. This volition save a significant corporeality of compile time.
  • The--disable-shared option means that nosotros don't want to build the new standard C++ runtime library equally a DLL that's shared with other C++ applications on the system. Information technology's totally possible to make C++ executables work with such DLLs, only it takes intendance not to introduce conflicts with C++ executables created past older or newer versions of GCC. That's something distribution maintainers need to worry nigh; non usa. Allow's just avert the additional headache.
  • By default, the new version of GCC will be installed to/usr/local in Cygwin's virtual filesystem. This volition get in easier to launch the new GCC, since/usr/local/bin is already listed in Cygwin'sPATH environment variable. However, if you're using an existing Cygwin installation, it might prove difficult to uninstall GCC from/usr/local later on (if you then choose), since that directory tends to contain files from several dissimilar packages. If you lot prefer to install the new GCC to a different directory, add the option--prefix=/path/to/directory to the in a higher placeconfigure command.

Nosotros're non going to build a new Binutils, which GCC relies on, because the existing Binutils provided past Cygwin is already quite recent. Nosotros're besides skipping a couple of packages, namely ISL and CLooG, which means that the new compiler won't exist able to utilise any of the Graphite loop optimizations.

Side by side, nosotros'll really build the new GCC compiler suite, including C, C++ and the standard C++ library. This is the longest step.

The-j4 choice lets the build procedure spawn up to four kid processes in parallel. If your car's CPU has at least 4 hardware threads, this option makes the build procedure run significantly faster. The main downside is that it jumbles the output messages generated during the build process. If your CPU has even more hardware threads, you lot can specify a college 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 mistake the first time I ran with-j4. Bad luck on my part. If that happens to y'all, running the aforementioned command a second fourth dimension should allow the build process to finish successfully. Also, when specifying higher numbers with-j, there are often strange error messages at the end of the build procedure involving "jobserver tokens", only they're harmless.

In one case that'south finished, install the new compiler:

This installs several executables to/usr/local/bin; it installs the standard C++ library'southward include files to/usr/local/include/c++/4.9.2; and it installs the static standard C++ library to/usr/local/lib, among other things. Interestingly, it doesnot install a new standard C library! The new compiler volition continue to use the existing arrangement C library that came with Cygwin.

If, afterwards, you lot decide to uninstall the new GCC compiler, you take several options:

  • If y'all installed GCC to a directory other than/usr/local, and that directory contains no other files, you tin simply delete that directory.
  • If y'all installed GCC to/usr/local, and there are files from other packages mixed into the same directory tree, you can run thelist_modifications.py script from this postal service to determine which files are safe to delete from/usr/local.
  • Y'all tin simply uninstall Cygwin itself, by deleting theC:\cygwin64 folder in Windows, along with its associated Start menu entry.

4. Test the New Compiler

All right, let'southward compile some lawmaking that uses generic lambdas! Generic lambdas are part of the C++xiv standard. They let yous laissez passer arguments to lambda functions asauto (or any templated blazon), like the one highlighted below. Create a file namedexamination.cpp with the following contents:

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

You tin add files to your home directory in Cygwin using whatever Windows-based text editor; merely save them to the folderC:\cygwin64\home\Jeff (or similar) in Windows.

Start, let's run across what happens when we try to compile it using the organization GCC compiler provided by Cygwin:

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

If the organization compiler version is less than 4.9, compilation volition fail:

Now, allow's try it again using our freshly congenital GCC compiler. The new compiler is already configured to locate its include files in/usr/local/include/c++/four.9.ii and its static libraries in/usr/local/lib. All we need to do is run it:

$ g++-4.9.2 -std=c++fourteen test.cpp $ ./a.exe          

It works!

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

Source: https://sefidian.com/2020/05/09/installing-g-c-compiler-on-windows/

Posted by: aguilarpreve1968.blogspot.com

0 Response to "How To Install Gcc Compiler In Cygwin"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel