Using mingw on windows

Using MinGW and Cygwin with Visual C++ and Open Folder

Building cross-platform C and C++ code is easier than ever with Visual Studio 15.3 Preview 4. The latest preview improves support for alternative compilers and build environments such as MinGW and Cygwin. MinGW (Minimalist GNU for Windows), in case you are not familiar with it, is a compiler in the GCC family designed to run natively on Windows. If you are interested in a quick rundown of this new functionality, check out our latest GoingNative episode on Channel 9.

Most MinGW installations, however, include much more than just a compiler. Most distributions of MinGW include a whole host of other tools that can be used to build and assemble software on Windows using the familiar GNU toolset. MinGW build environments often contain an entire POSIX development environment that can be used to develop both native Windows software using POSIX build tools and POSIX software that runs on Windows with the help of an emulation layer.

Please download the preview and try out the latest C++ features. You will need to also make sure you install the Linux Tools for C++ workload in addition to Desktop C++ to use these new features. You can learn more about Open Folder on the Microsoft docs site. We are looking forward to your feedback.

Why MinGW

There are three reasons why you might want to use MinGW on Windows. The first is simply compiler compatibility. We all love MSVC, but the reality is that some codebases are designed from the ground up under the expectation that they will be built with GCC. This is especially true for many cross-platform projects. Porting these codebases to support MSVC can be a costly endeavor when all you want to do is get up and running with your code. With MinGW you can be up and running in minutes instead of days.

There is, however, an even more compelling reason to use MinGW than source compatibility with GCC. MinGW environments are not just a compiler, but include entire POSIX build environments. These development environments allow cross-platform projects to build on Windows with few if any modifications to their build logic. Need Make or AutoTools, it’s already installed – if you are using an environment like MSYS2 nearly every tool you might need is only a single package management command away.

Finally, some MinGW distributions such as MSYS2 allow you to build native POSIX software on Windows without porting the code to Win32. This is accomplished by an emulation layer that allows native POSIX tools to run on Windows. This same layer is what allows all your favorite POSIX build tools to run in the MinGW environment.

Install MinGW on Windows

Getting started with MinGW is simple once you have installed the latest Visual Studio Preview. First, you will need to make sure that you select the C++ workload when you install Visual Studio. Next, you will need to download MinGW itself. There are actually many ways to install MinGW. If you are particularly adventurous you can build it from source, but it is much easier to install any of the popular binary distributions. One of the more popular distributions is MSYS2 (getting started guide). A standard MSYS2 installation installs three build environments: POSIX build environments to natively target 32-bit and 64-bit Windows, and an emulation layer to build POSIX software that targets Windows.

If you have a particular project in mind that you are working with, it is also worth checking out if they have any project-specific instructions on how to install MinGW. Some projects even include their own custom tailored MinGW distributions.

Use MinGW with Visual Studio

It has been possible to use GCC based compilers with Visual Studio projects for some time already, but many cross-platform projects that build with MinGW on Windows are not organized into Solution and Visual C++ project files. Creating these assets for a real-world project can be time consuming. To streamline onboarding cross-platform projects into Visual Studio, we now support opening folders directly, and in the latest preview it is easier than ever to use alternative compilers and build environments such as MinGW.

Читайте также:  Realtek ethernet diagnostic utility для windows 10

With “Open Folder” you can edit your code with full IntelliSense, build, and debug with the same fidelity as is available with full Solution and C++ project files. However, instead of authoring hundreds of lines of XML you just need to write a small amount of JSON. Even better, you only need to write the JSON for the features you need. For instance, if you only want to edit code in the IDE and stick to the command line for everything else, you only need to write a few lines of JSON to enable IntelliSense.

Edit with Accurate IntelliSense

To get the most out of IntelliSense when using “Open Folder” you will need to create a CppProperties.json file. You can create this file by selecting “Project->Edit Settings->CppProperties.json…” from the main menu.

This file is automatically populated with four configurations: “Debug” and “Release” for the x86 and x64 architectures. If you don’t need all of these configurations you can remove them to reduce clutter. Next, you will need to configure a few options to get IntelliSense that is consistent with your MinGW build.

In each configuration, you may notice an “intelliSenseMode” key. For MinGW and other GCC based compilers you should set this to “windows-clang-x86” or “windows-clang-x64” depending on your architecture.

Next, you will need to add the include paths for your project. Configuration specific include paths can be added to the “includePath” array under each configuration. You can add project-wide include paths here as well but it may be easier to add them to the “INCLUDE” environment variable, by adding an “environment” block to your configuration file as a peer to “configurations”:

Note: MINGW_PREFIX should point to your MinGW installation, if you installed MSYS2 with default settings this directory will be “C:/msys64/mingw64”.

Most GCC based compilers, including MinGW, automatically include certain system header directories. For full IntelliSense, you will need to add these to the include path list. You can get a list of these standard includes by running:

Build with MinGW

Once you have set up IntelliSense (with “MINGW_PREFIX” and its related environment variables defined and added to “PATH”), building with MinGW is quite simple. First, you will need to create a build task. Right click your build script (or any other file you would like to associate with the task) and select “Configure Tasks”:

This will create a “tasks.vs.json” file if you don’t already have one and create a stub. Since MinGW and its tools are already on the PATH, as configured in CppProperties.json, you can configure the task to use them like this:

This example is simple – it only builds one file – but this can call into Make or any other build tools supported by MinGW as well. Once you save this file, you should have a “Build” option available for any files matched by the “appliesTo” tag.

Selecting “Build” from the context menu will run the command and stream any console output to the Output Window.

Debug MinGW Applications

Once you have configured your project to build, debugging can be configured with by selecting a template. Once you have built an executable, find it in the folder view and select “Debug and Launch Settings” from the executable’s context menu in the Solution Explorer:

This will allow you to select a debugger template for this executable:

This will create an entry in the “launch.vs.json” file that configures the debugger:

In most cases, you won’t have to modify this at all, as long as you defined “MINGW_PREFIX” in the “CppProperties.json” file. Now you are ready to edit, build, and debug the code. You can right click the executable and select “Debug” in the context menu or select the newly added launch configuration in the debug dropdown menu to use F5. You should be able to use breakpoints and other debugging features like the Locals, Watch, and Autos Windows. If you are having trouble hitting breakpoints, make sure your build command was configured to emit GDB compatible symbols and debugging information.

Finally, to complete the full inner loop, you can add an “output” tag to your build task in “tasks.vs.json”. For instance:

Читайте также:  Lookup ip address linux

What About Cygwin and Other Compilers in the GCC Family

While we have discussed MinGW specifically in this post, it is worth keeping in mind that very little of the content above is specific to MinGW. These topics apply equally well to other compilers and build environments so long as they can produce binaries that can be debugged with GDB. With minimal modification, the instructions under the “Use MinGW with Visual Studio” section above should work fine with other environments such as Cygwin and even other compilers like Clang. In the future, Open Folder will support an even greater variety of compilers and debuggers – some out of the box, some with a little bit of extra configuration that may be specific to your projects.

Send Us Feedback

To try out the latest and greatest C++ features and give us some early feedback, please download and install the latest Visual Studio 2017 Preview. As always, we welcome your feedback. Feel free to send any comments through e-mail at visualcpp@microsoft.com, through Twitter @visualc, or Facebook at Microsoft Visual Cpp.

If you encounter other problems with Visual Studio 2017 please let us know via Report a Problem, which is available in both the installer and the IDE itself. For suggestions, let us know through UserVoice. We look forward to your feedback!

How To install MinGW on Windows 10 (GCC & G++)

MinGW, a contraction of “Minimalist GNU for Windows”, is a minimalist development environment for native Microsoft Windows applications.

Downloading MinGW

  1. open http://www.mingw.org/
  2. Click Download Button as shown in the picture below.

3. As soon as you click download button on mingw website The following page will open in your browser (from the SourceForge.net web site).

4. The following exe file will be downloaded with the name mingw-get-setup.exe

5. Click mingw-get-setup.exe

6. Click install

7. Click continue

8. Click continue

9. The following pop-up window will appear. Pleas make sure that you selected all the check-boxes. e.g. mingw32-base, mingw32-gcc=g++, msys-base and so on.

10. Click on Installation > Apply Changes as shown in the picture below.

11. wait for the process to complete. once you see successful installation message close the window. Click Close.

12. Now we will set environment variable to use gcc and g++ command from terminal.

Windows 10 and Windows 8
  1. In Search, search for and then select: System (Control Panel)
  2. Click the Advanced system settings link.

  • Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New .

  • In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable.
  • Copy C:\MinGW\bin .
  • Click OK.
  • Close all remaining windows by clicking OK.

  • Reopen Command prompt window, and type gcc . if you see the following output as shown in the picture below the mingw is installed successfully.

Video : How To install MinGW on Windows 10 (GCC & G++)

How To Install MinGW on Windows

Provides all the steps required to install MinGW on Windows and getting started with C or C++ programming.

MinGW also called as Minimalistic GNU for Windows is a popular compiler for C and C++ and used for the development of native MS-Windows applications. It does not depend on any 3rd party tools or libraries but relies on the several DLLs provided by Microsoft as components of the operating system. Out of these DLLs, MSVCRT.DLL i.e. Microsoft C runtime library is the primary one. Apart from the system components, the threaded applications must use freely distributable thread support DLL, provided as part of MinGW itself. You may consider using Cygwin for POSIX application deployment.

Below listed are the features and components provided by MinGW. You may also refer MinGW for more details.

  • A port of the GNU Compiler Collection (GCC), including C, C++, ADA and Fortran compilers;
  • GNU Binutils for Windows (assembler, linker, archive manager)
  • A command-line installer, with optional GUI front-end, ( mingw -get) for MinGW and MSYS deployment on MS-Windows
  • A GUI first-time setup tool ( mingw -get-setup), to get you up and running with mingw -get.

In this tutorial, we will install MinGW on windows and write, compile, and execute our Hello World program in C++.

Step 1 — Download MinGW

Go to the Download Page to start downloading mingw -w64. It will show various download options as shown in Fig 1.

Download MinGW-W64-builds as highlighted in Fig 1.

You may also download and install MinGW Installation Manager in case you are planning only for the 32-bit compiler. The MinGW-W64 provides both 32-bit and 64-bit compilers.

Download MinGW Installation Manager as highlighted in Fig 2.

Step 2 — Install MinGW-W64

Now execute the MinGW-W64-builds executable downloaded by us in the previous step. It will show the welcome screen as shown in Fig 3.

Click on the Next Button to continue with the installation. It will show the settings screen as shown in Fig 4.

Note that I have selected x86_64 architecture in order to support 64-bit instructions. You may continue with i686 for 32-bit instructions. Also, I have selected the posix option of Threads settings for programs involving multithreading. You may select the win32 option based on your needs. Now click on the Next Button to continue with the installation. The next screen asks for the installation path as shown in Fig 5.

Make sure that you provide an installation path without any spaces. Now click on the Next Button to finish the installation.

It might show you error specific to fail to download. I tried a few times and got success in 3rd attempt. You may also continue with manual installation in case it failed multiple times. You can simply download the archive of MinGW-W64 and extract it to the desired location.

It will show the download progress and status as shown in Fig 6, Fig 7, and Fig 8.

Now click on the Next Button after download completes. It will show the success message as shown in Fig 9.

Click on the Finish Button to close the installer. Now add the bind directory of MinGW-W64 to the system path as shown in Fig 10.

Step 3 — Install MinGW

In this step, we will install the MinGW distributed by the official website as shown in Fig 2. Execute the installer downloaded in previous steps. It will show the welcome screen as shown in Fig 11.

Click on the Install Button to start the installation. It will ask for the installation directory as shown in Fig 12.

Click on the Continue Button to start the installation. It will show the progress as shown in Fig 13 and Fig 14.

Click on the Continue Button to launch the installation manger as shown in Fig 15.

Choose the package GCC as shown in Fig 16.

Click on the Apply Button to apply the changes as shown in Fig 17.

Click on the Apply Changes Button . It will show the confirmation message as shown in Fig 18.

Click on the Apply Button to install GCC. It will show the Package progress as shown in Fig 19 and Fig 20.

Click on the Close Icon and also close the installation manager to complete the installation of the compiler required to compile the programs.

You may add the MinGW path to bin directory which is C:\cpp\mingw\bin in my case to system path as we did for MinGW-W64. Make sure that you keep only one compiler path at a time among MinGW and MinGW-W64.

Step 4 — Getting started with C — Hello World

Write your first C program as shown below and save in a file hello.c.

Compile and execute the program using the command as shown below.

It will compile the program and generate the executable i.e. hello.exe. We can simply type hello to execute the program. It will print Hello World on the console as shown in Fig 21.

Step 5 — Getting started with C++ — Hello World

We can repeat the previous step to write the Hello World program in C++. Write your first C++ program as shown below and save it to hello.cpp.

Compile and execute the program using the command as shown below.

It will compile the program and generate the executable i.e. hello.exe. We can simply type hello to execute the program. It will print Hello World on the console as shown in Fig 22.

This is how we can install MinGW and MinGW-W64 and configure the system path to access the executables from the command line. We also wrote our first C and CPP programs, compiled and executed them to print Hello World on the console.

Читайте также:  Не регулируется громкость наушников windows 10
Оцените статью