Events

:

:

Elektronik | Funk | Software

Der Technik-Blog

  • Social Media

    Werbung:


    New Posts


    Events

    • Keine zukünftigen Events vorhanden

    The Tech-Blog

    C++ Cross Plattform Coding Linux Windows

    Cross-Platform C++ Programming

    Alex @ AEQ-WEB

    Visual Studio Code is a lightweight, cross-platform editor that can be used for developing C++ projects on Windows, macOS, and Linux. With CMake, it becomes possible to create cross-platform C++ code that can be compiled on different systems like Windows, Linux, or even a Raspberry Pi. MinGW64 acts as a compiler for Windows, enabling the creation of executable .exe files. The following guide describes the installation of these three tools to set up a C++ development environment and produce an executable .exe file.

    Installation of Visual Studio Code

    Visual Studio Code (VSC) is a good choice as a development environment because it is free and available cross-platform. Compared to Visual Studio Community or paid Enterprise versions, Visual Studio Code has a smaller memory footprint, making it an excellent choice for C++ development. The installation file for Visual Studio Code can be downloaded directly from e Microsoft’s download page. The installation process is similar to other programs and does not require special inputs or configurations. After installing VSC, proceed directly to the installation of CMake.

    Installation of CMake

    CMake is a cross-platform build tool that allows the creation of C++ code which can be compiled on different systems. For example, a program can be written and tested on Windows and later compiled on Linux or a Raspberry Pi with a compiler tool. The installation file for CMake can be downloaded from the official CMake website. CMake is installed and set up on Windows via an installer.

    Werbung:

    Installation of the MinGW64 Compiler

    The MinGW64 compiler is required to compile C++ code on Windows and create executable files (.exe). MinGW64 is available as a ZIP file and is around 1.5 GB after extraction. The archive is unpacked into the Windows Program folder (C:\ProgramFiles\mingw64).

    To make the compiler accessible system-wide, the path to the MinGW64 bin folder (e.g., C:\ProgramFiles\mingw64\bin) must be specified. In Windows, the "Advanced System Settings" allow for adding environment variables. Here, the system variable "Path" is edited to include the path to the MinGW64 bin folder.

    Starting Visual Studio Code

    In VSC, two extensions must be installed. The following extensions are added in VSC:

  • CMake Tools: Provides CMake support in Visual Studio Code
  • C/C++ Extension Pack: Extension for C development in VSC
  • Werbung:

    Hello World Example

    New projects do not need to be set up in VSC; instead, an existing folder is opened. For this example, create a folder called "Visual Studio Code" under your documents. For each project, another subfolder (e.g., HelloWorld) is recommended. Once the empty folder is opened, you can create program files and folders. For an initial C++ program, create two files. The first file is in the main directory of the project folder and is named CMakeLists.txt. The contents are as follows:

    # Set the minimum required version of CMake
    cmake_minimum_required(VERSION 3.10)
    
    # Project name
    project(HelloWorld)
    
    # Set the C++ standard
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_REQUIRED True)
    
    # Create the executable program
    add_executable(HelloWorld src/main.cpp)
    

    The second file goes in the subfolder "src" and is named main.cpp. This file contains the actual C++ program:

    #include 
    
    int main() {
        std::cout << "Hello, World!" << std::endl;
        std::cin.get();
        return 0;
    }
    

    Compiling the Program

    Now, you need to create an executable program from these two files using the GCC compiler. In VSC, press the key combination [CTRL]+[SHIFT]+[P] to open the input field and enter the following command: "CMake: Build". The build process will now start, and the compiler will create a folder named "Build" in the directory. In this folder, you will find the executable file "HelloWorld.exe".

    Werbung:

    Compiling Code on Linux

    This example can also be compiled and run on Linux. A guide for this process is available in this article.


    Info: This page was automatically translated and may contain errors
    122X122

    About the Author

    Alex, the founder of AEQ-WEB. He works for more of 10 years with different computers, microcontroller and semiconductors. In addition to hardware projects, he also develops websites, apps and software for computers.

    Top articles in this category:

    Vaisala RS41 Radiosonde Firmware Flash

    Radiosonde RS41 Firmware Flash

    • Video
    • DE/EN

    Every day hundreds of meteorological radiosondes fall from the sky. In this article we convert a radiosonde into a GPS tracker for APRS, RTTY & CW

    read more
    SenseCAP T1000 Payload Decoder

    SenseCAP T1000 Payload Decoder

    • DE/EN

    Alternative payload decoder for the SenseCAP T1000 LoRaWAN GPS tracker. Compatible with TTN Mapper, LoWTrack and other apps.

    read more

    Social Media

    Werbung:


    New Posts


    Events

    • Keine zukünftigen Events vorhanden