Sidewalk: The IoT network from Amazon
08.05.2024
Elektronik | Funk | Software
Der Technik-Blog
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.
C++ Programm Compile on Raspberry Pi & Linux
C++ Example Code IP-Address Viewer
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.
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.
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.
In VSC, two extensions must be installed. The following extensions are added in VSC:
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:
#includeint main() { std::cout << "Hello, World!" << std::endl; std::cin.get(); return 0; }
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".
This example can also be compiled and run on Linux. A guide for this process is available in this article.
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 moreAlternative payload decoder for the SenseCAP T1000 LoRaWAN GPS tracker. Compatible with TTN Mapper, LoWTrack and other apps.
read moreAEQ-WEB © 2015-2024 All Right Reserved