Как установить gcc windows
How to install the C language GCC compiler on Windows
On Linux, gcc is install by default and you can start to compile and execute C language code almost right away!
That’s not the case on Windows…
I have been struggling with how to do the same thing on Windows 10 for some time, but I finally succeeded
Here’s a video in which I explain the procedure:
Note: The procedure I describe here will not only allow you to install gcc, but also g++, gfortran, and many other useful tools that you usually only get in linux OS (like ls or grep)
1- What I want to teach you here
If you want a simple way to create programs based on C, C++, Fortran, etc… you will have to install a software with can compile the code you write into code that the machine understands
Such program is called a “compiler”
The most well know compiler for C language is the GNU compiler called GCC.
There are actually several compilers which go together like a suite:
Why using the gcc compiler?
If you are on Windows, you probably heard about software such as visual studio from Microsoft which also you to write and compile C and C++ code as well.
That’s true, and it’s totally fine if you want to use it…
I am personally not such a big fan of Visual Studio because of the following reasons:
Because of that, I find that I kind of takes out the fun of programming and seeing immediately the result of what you did…
Now, for large pieces of software, visual studio is probably the way to go
2- How to use the gcc compiler?
Once installed on your machine, gcc is just a piece of cake to use to compile a simple c language code
Step 1: Write your c code
For example, let’s take this Hello World example
Step 2: Compile using gcc
Write the following line of code into your terminal:
This will generate an executable binary file called helloworld.exe which can be used to run your code
Step 3: Execute your code
Just go into the directory where your executable is and run it by writing “helloworld.exe”
2- The principle
Now that you understand how it can be easy to start with writing C code, let’s talk about the difficult part…
How to actually install gcc on Windows…
The reason it is easy to install compilers and other kind of open source software on linux is because you have a very powerful command line terminal called bash which handles the installation, uninstallation and upgrade of software using a software called “apt” on debian-based linux systems.
On Windows, if you want to have gcc (and the other compilers too), you have to download the source code and find a way to compile it…
For that, you will need to install first other software called pre-requisites which will also need to be compiled, etc…
You can spend several days trying to do that if you are really motivated
I will present you another way much simplier!
For that I will have to install a software called MSYS2, which is an “easy” way to give some linux feel to your Windows PC and able it to install programs almost as easily as in linux…
You will be able to install gcc just with one command line like this:
3- Installing MSYS2 on your PC
What is MSYS2?
According to their website, MSYS2 is a software distribution and building platform for Windows
The Website: https://www.msys2.org/
Installing it is actually a peace of cake
Just download the correct installer and launch it with admin rights and you are good to go
Expected something more complex?
Once you installed it, you will see 3 programs appear in your list of programs:
Run the 3rd one MSYS2 MSYS to open a special command window in which you can input commands and start to install programs
The package management system which is equivalent to apt-get on linux is called pacman
When you install MSYS2 for the first time, you have to update pacman using the following command:
4- Installing GCC and other development tools with the pacman package management system
Then you can start to install gcc and other developer tools using pacman like this:
This command will install first a set of development software included in a package called base-devel and then it will install gcc, vim and cmake
vim is optional, but always good to have 😉
(You can also install emacs very easily in the same way)
In the package base-devel, you have 53 useful developement tools that can be installed:
5- Last Important Step: Add Executables to your Windows PATH
Now you are able to install all those packages easily, but how to access them through the normal windows command line?
For that, you have to add the two following directories to your PATH:
To add anything to your PATH in Windows 10:
1- Search “Advanced System Settings” in the search bar
2- Open the “environment variables” window, click on the PATH variable and click on “Edit”
3- Click on the “New” button and add the 2 following directories to your PATH
Important Note: This adds a lot of executables to your path which might conflict with other applications. The usr\bin\ directory contains the whole slew of executables listed above. There is a lot of unnecessary stuff in that directory.
4- Click on OK on all the windows and open a new Command Window and you will be able to use gcc into your windows command prompt!
That’s all for today, hope you understand better now how to install and use GCC and other linux tools on windows!
I will write new articles soon about how to develop simple programs in C.
Let me know through the comments if there is something special that you want to understand!
PS: If you like what I write, subscribe to the newsletter and help me to spread the knowledge by sharing this article! We all win by learning from each other and making the engineering knowledge more accessible 🙂 THANK YOU!
Установка GNU C (gcc) для Windows (MinGW)
Материал из биософт-м
! | Данная информация предназначена только только для IT-специалистов по системной интеграции модулей БИОСОФТ-М. (см. Руководства пользователя к программным продуктам) |
Компилятор нужно было приготовить так, чтобы архив просто записать в
что бы он работал без всяких глобальных настроек системы. Мобильно, удобно для переноса между компами. Ниже приведена правильная последовательность действий дающая такой результат.
Все локально
Базовый MinGW не требует никаких обязательных настроек системы, реестра, путей и т.п., даже если иное вы прочитаете на их сайте.
Я специально отделяю эту инсталляцию от других возможных инсталляций GCC в системе. Она не вызывает конфликта ни с QT ни с SDK для контроллеров.
Они требуют прописывать PATH, я делаю это не системно а локально в компиляционных скриптах. Так мы точно знаем какой компилятор откуда запустился.
Откуда все взялось знать не обязательно.
Откуда взялось
Исходное скачивание проводится на компе с интернетом.
Я не хочу менять никаких системных настроек. Хочу, чтобы компилятор копировался на другие компы и был готов к работе без всяких подготовительных процедур.
Предупреждаю, что эта процедура может привести к скачиванию более новых версий и соответственно к несовместимости с какими то исходниками отлаженными под то что выдано выше.
mingw-get
Распаковываем в C:\MinGW.
Запускаем cmd.exe и пишием:
(далее текущая директория C:\MinGW\bin подразумевается)
Проверяем
По мининимуму больше ничего не нужно. Компиляцию будет организовывать Jam.
Лицензия
Мы не поставляем ни GCC ни MinGW ни как часть наших инсталляций, ни как неотъемлемую часть SDK. Они не являются составляющей частью наших продуктов ни в каком виде. Если какая либо поставка утилит будет включать GCC или MinGW то все связанные с ними исходники требуемые лицензиями и копия лицензии приложены и либо доступны для скачивания с нашего сайта либо входят в поставляемый архив.
Installing g++ (C++ Compiler) on Windows
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.
You should now be able to run g++ from a DOS command prompt window. For example, to compile a file called C:\mine\hello.cpp, connect to the C:\mine folder and enter
You’ll then be able to run the compiled program by entering hello in the DOS command prompt window.
If you’d like to learn more about 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: full.exe at this point. Your g++ compiler is installed under C:\cygnus.
Several modern C++ features are currently missing from Visual Studio Express, and from the system GCC compiler provided with many of today’s 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 following guide will help you install the latest GCC on Windows, so you can experiment with generic lambdas and other cutting-edge C++ features. You’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 as little as 15 minutes.
[Update: As a commenter points out, you can also install native GCC compilers from the MinGW-w64 project without needing Cygwin.]
1. Install Cygwin
First, download and run either the 32- or 64-bit version of the Cygwin installer, depending on your version of Windows. Cygwin’s setup wizard will walk you through a series of steps. If your machine is located behind a proxy server, make sure to check “Use Internet Explorer Proxy Settings” when you get to the “Select Your Internet Connection” step.
When you reach the “Select Packages” step (shown below), don’t bother selecting any packages yet. Just go ahead and click Next. We’ll add additional packages from the command line later.
If you already have Cygwin installed, it’s a good idea to re-run the installer to make sure it 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. You can add them all in one fell swoop. Just open a Command Prompt (in Windows), navigate to the folder where the Cygwin installer is located, and run the following command:
A window will pop up and download all the required packages along with their dependencies.
At this point, you now have a working GCC compiler on your system. It’s not the latest version of GCC; it’s whatever version the Cygwin maintainers chose as their system compiler. At the time of writing, that’s GCC 4.8.3. To get a more recent version of GCC, you’ll have to compile it yourself, using the GCC compiler you already have.
3. Download, Build and Install the Latest GCC
Open a Cygwin terminal, either from the Start menu 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.
To download and extract the latest GCC source code, enter the following commands in the Cygwin terminal. If you’re following this guide at a later date, there will surely be a more recent version of GCC available. I used 4.9.2, but you can use any version you like. Keep in mind, though, that it’s always best to have the latest Cygwin packages installed when building the latest GCC. Be patient with the tar command; it takes several minutes.
Here’s a description of the command-line options passed to configure :
We’re not going to build a new Binutils, which GCC relies on, because the existing Binutils provided by Cygwin is already quite recent. We’re also skipping a couple of packages, namely ISL and CLooG, which means that the new compiler won’t be able to use any of the Graphite loop optimizations.
Next, we’ll actually build the new GCC compiler suite, including C, C++ and the standard C++ library. This is the longest step.
Once that’s finished, install the new compiler:
If, later, you decide to uninstall the new GCC compiler, you have several options:
4. Test the New Compiler
All right, let’s compile some code that uses generic lambdas! Generic lambdas are part of the C++14 standard. They let you pass arguments to lambda functions as auto (or any templated type), like the one highlighted below. Create a file named test.cpp with the following contents:
You can add files to your home directory in Cygwin using any Windows-based text editor; just save them to the folder C:\cygwin64\home\Jeff (or similar) in Windows.
First, let’s see what happens when we try to compile it using the system GCC compiler provided by Cygwin:
If the system compiler version is less than 4.9, compilation will fail:
Preshing on Programming
Several modern C++ features are currently missing from Visual Studio Express, and from the system GCC compiler provided with many of today’s 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 following guide will help you install the latest GCC on Windows, so you can experiment with generic lambdas and other cutting-edge C++ features. You’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 as little as 15 minutes.
[Update: As a commenter points out, you can also install native GCC compilers from the MinGW-w64 project without needing Cygwin.]
1. Install Cygwin
First, download and run either the 32- or 64-bit version of the Cygwin installer, depending on your version of Windows. Cygwin’s setup wizard will walk you through a series of steps. If your machine is located behind a proxy server, make sure to check “Use Internet Explorer Proxy Settings” when you get to the “Select Your Internet Connection” step.
When you reach the “Select Packages” step (shown below), don’t bother selecting any packages yet. Just go ahead and click Next. We’ll add additional packages from the command line later.
If you already have Cygwin installed, it’s a good idea to re-run the installer to make sure it 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. You can add them all in one fell swoop. Just open a Command Prompt (in Windows), navigate to the folder where the Cygwin installer is located, and run the following command:
A window will pop up and download all the required packages along with their dependencies.
At this point, you now have a working GCC compiler on your system. It’s not the latest version of GCC; it’s whatever version the Cygwin maintainers chose as their system compiler. At the time of writing, that’s GCC 4.8.3. To get a more recent version of GCC, you’ll have to compile it yourself, using the GCC compiler you already have.
3. Download, Build and Install the Latest GCC
Open a Cygwin terminal, either from the Start menu 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.
To download and extract the latest GCC source code, enter the following commands in the Cygwin terminal. If you’re following this guide at a later date, there will surely be a more recent version of GCC available. I used 4.9.2, but you can use any version you like. Keep in mind, though, that it’s always best to have the latest Cygwin packages installed when building the latest GCC. Be patient with the tar command; it takes several minutes.
Here’s a description of the command-line options passed to configure :
We’re not going to build a new Binutils, which GCC relies on, because the existing Binutils provided by Cygwin is already quite recent. We’re also skipping a couple of packages, namely ISL and CLooG, which means that the new compiler won’t be able to use any of the Graphite loop optimizations.
Next, we’ll actually build the new GCC compiler suite, including C, C++ and the standard C++ library. This is the longest step.
Once that’s finished, install the new compiler:
If, later, you decide to uninstall the new GCC compiler, you have several options:
4. Test the New Compiler
All right, let’s compile some code that uses generic lambdas! Generic lambdas are part of the C++14 standard. They let you pass arguments to lambda functions as auto (or any templated type), like the one highlighted below. Create a file named test.cpp with the following contents:
You can add files to your home directory in Cygwin using any Windows-based text editor; just save them to the folder C:\cygwin64\home\Jeff (or similar) in Windows.
First, let’s see what happens when we try to compile it using the system GCC compiler provided by Cygwin:
If the system compiler version is less than 4.9, compilation will fail:
Check out Plywood, a cross-platform, open source C++ framework:
Recent Posts
how to install gcc on windows 7 machine?
I have MinGW on my windows 7 machine. I wish to install and use complete gcc for C compiler. I found there is no single pre-compiled ready-made installation file for this purpose. I checked the following page : http://gcc.gnu.org/install/ It is difficult and I find it above my level of understanding. Could any one please provide me step by step guidance along with links?
5 Answers 5
EDIT Since not so recently by now, MinGW-w64 has «absorbed» one of the toolchain building projects. The downloads can be found here. The installer should work, and allow you to pick a version that you need.
Note the Qt SDK comes with the same toolchain. So if you are developing in Qt and using the SDK, just use the toolchain it comes with.
Another alternative that has up to date toolchains comes from. harhar. a Microsoft developer, none other than STL (Stephan T. Lavavej, isn’t that a spot-on name for the maintainer of MSVC++ Standard Library!). You can find it here. It includes Boost.
Another option which is highly useful if you care for prebuilt dependencies is MSYS2, which provides a Unix shell (a Cygwin fork modified to work better with Windows pathnames and such), also provides a GCC. It usually lags a bit behind, but that is compensated for by its good package management system and stability. They also provide a functional Clang with libc++ if you care for such thing.
I leave the below for reference, but I strongly suggest against using MinGW.org, due to limitations detailed below. TDM-GCC (the MinGW-w64 version) provides some hacks that you may find useful in your specific situation, although I recommend using vanilla GCC at all times for maximum compatibility.
GCC for Windows is provided by two projects currently. They both provide a very own implementation of the Windows SDK (headers and libraries) which is necessary because GCC does not work with Visual Studio files.
The older mingw.org, which @Mat already pointed you to. They provide only a 32-bit compiler. See here for the downloads you need:
Alternatively, download mingw-get and use that.
The newer mingw-w64, which as the name predicts, also provides a 64-bit variant, and in the future hopefully some ARM support. I use it and built toolchains with their CRT. Personal and auto builds are found under «Toolchains targetting Win32/64» here. They also provide Linux to Windows cross-compilers. I suggest you try a personal build first, they are more complete. Try mine (rubenvb) for GCC 4.6 to 4.8, or use sezero’s for GCC 4.4 and 4.5. Both of us provide 32-bit and 64-bit native toolchains. These packages include everything listed above. I currently recommend the «MinGW-Builds» builds, as these are currently sanctioned as «official builds», and come with an installer (see above).
For support, send an email to mingw-w64-public@lists.sourceforge.net or post on the forum via sourceforge.net.
Both projects have their files listed on sourceforge, and all you have to do is either run the installer (in case of mingw.org) or download a suitable zipped package and extract it (in the case of mingw-w64).
There are a lot of «non-official» toolchain builders, one of the most popular is TDM-GCC. They may use patches that break binary compatibility with official/unpatched toolchains, so be careful using them. It’s best to use the official releases.