Skip to content

Latest commit

 

History

History
86 lines (69 loc) · 4.18 KB

install_mingw_win.md

File metadata and controls

86 lines (69 loc) · 4.18 KB

Chocolate is a package manager for Windows

  1. Open Windows PowerShell as an Admin
  2. Run command: Get-ExecutionPolicy
    If you get "Restricted", then run: Set-ExecutionPolicy Bypass -Scope Process or Set-ExecutionPolicy AllSigned and accept by typing "yes"
  3. Run command: [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
  4. Check by: choco

Whole process should look like this

2. Install MinGW

  1. Run command: choco install mingw
  2. After installation run command: refreshenv or rerun PowerShell (remember that it should be run as admin)
  3. Check that all is ok: g++ --version

Whole process should look like this

3. Install Cmake

  1. Run command: choco install cmake --installargs 'ADD_CMAKE_TO_PATH=User'
  2. Reboot the system
    After installation I got an error: "The term 'cmake' is not recognized" because of lack of environment variables. Reboot helps
  3. Check that all is ok: cmake --version

Whole process should look like this

4. Install VSCode

  1. Download VSCode: https://code.visualstudio.com/download
  2. Install by downloaded installer
    During installation set the point with environment variables
  3. Reboot the system

It is possible to install VSCode by choco but default installer is good.

5. Setup VSCode

  1. Install extensions: cmake tools, С/С++
    Optional extensions: git graph, git lens, back&forth
    Click on extension panel, use search box, and press button Install
  2. Setup cmake extension with MinGW
    Click CMake Tools/Manage/Extension Settings
  3. Scroll up to Cmake: Generator and enter: MinGW Makefiles

6. First Cmake project

  1. Open folder (via VSCode) for a new project
    For dialog box "Trust the authors" answer yes
  2. Press F1. Enter cmake. Choose Cmake: Quick Start
  3. Choose MinGW compiler
  4. Input project name, e.g. hello_world
    Choose type of project Executable Open main.cpp
  5. For building press button build (look at the bottom)
  6. For running press button "Play" (around Build button)
  7. For debugging press "Bug" (around Build button) Breakpoint can be placed by clicking around line number
    For step-by-step debugging use hot keys: F10, F11, F5 or panel on the top

7. BONUS: boosted CMakeLists.txt

The autogenerated CMakeLists.txt is good, but it can be enhanced.
Lets create src folder and move main.cpp there. Other *.cpp files also should be placed there. Change the CMakeLists.txt:

cmake_minimum_required(VERSION 3.0.0)
project(my_project VERSION 0.1.0)

# program name
set(EXEC_NAME hello)
# set source folder
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src SUB_SOURCES)
# add sources to compilation
add_executable(${EXEC_NAME} ${SUB_SOURCES})
# add paths to include folders. Usually it is "include" folder, not "src"
target_include_directories(${EXEC_NAME} PRIVATE 
    ${CMAKE_CURRENT_SOURCE_DIR}/src)
# set the C++ standard
set_property(TARGET ${EXEC_NAME} PROPERTY CXX_STANDARD 17) #20

# set pedantic compiler which won't skip errors
#target_compile_options(${EXEC_NAME} PRIVATE -Wall -Wextra -Wpedantic -Werror)
# in case you need define
#target_compile_definitions(${EXEC_NAME} PRIVATE RUN_TESTS)

Sometimes you want to rebuild project from scratch. You can remove build folder or run f1->cmake:clean, cmake:configure