Compile on Windows

From LabRPS Documentation
Revision as of 11:11, 26 November 2024 by LabRPS (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Arrow-left.svg Previous: License

This page explains step by step how to compile LabRPS 0.1.0 on Windows using Microsoft's MSVC compiler. For information on using MSYS2/MinGW see Compile on MinGW. For other platforms see Compiling.

Prerequisites

Compiling LabRPS on Windows requires several tools and libraries.

Required

  • A compiler. LabRPS is tested with Visual Studio (MSVC)—other compilers may work, but instructions for use are not included here. Fore more details, see the section Compiler below.
  • Git (There are also GUI frontends available for Git, see the next section.)
  • CMake version 3.11.x or newer.
    Hint: Choosing the option Add CMake to the system PATH for all users when installing CMake will make CMake accessible from the Windows command prompt, which can be useful.
  • The LibPack. This is a single package containing all of the libraries necessary to compile LabRPS on Windows. Download the version of the LibPack that corresponds to the version of LabRPS you want to compile. To compile LabRPS 0.1.0 download the LibPack version 1.0.0. Extract the LibPack to a convenient location. (If your computer does not recognize the .7z extension, you must install the program 7-zip.)
    Note: It is highly recommended to compile LabRPS with the compiler version the LibPack is designed for. For example, you might run into problems compiling LabRPS 0.1.0 using MSVC 2017 because the LibPack is designed to be built with MSVC 2022 or newer.

Optional programs

  • A GUI frontend for Git. There are several frontends available, see this list. The main benefit of a frontend is that you don't have to learn the Git commands to get the source code of LabRPS or to send patches to the GitHub repository of LabRPS.

In the following we describe source code handling using the TortoiseGit frontend. This frontend integrates directly into Windows file explorer and has a large user community to get help in case you have problems.

  • NSIS is used to generate the LabRPS Windows installer.

Source code

Now you can get the source code of LabRPS:

Using a frontend

When using the Git frontend TortoiseGit:

  1. Create a new folder where the source code will be downloaded.
  2. Right-click on this folder in the Windows file explorer and select Git Clone in the context menu.
  3. A dialog will appear. In it, enter the URL for the LabRPS Git repository

https://github.com/LabRPS/LabRPS.git

and click OK.

The latest source code will be downloaded from the LabRPS Git repository and the folder will be tracked by Git.

Using the command line

To create a local tracking branch and download the source code, open a terminal (command prompt) and switch there to the directory you want the source, then type:

git clone https://github.com/LabRPS/LabRPS.git

Compiler

The default (recommended) compiler is MS Visual Studio (MSVC). Though it may be possible to use other compilers, for example gcc via Cygwin or MinGW, it is not tested or covered here.

You can get a free version of MSVC (for individual usage) by downloading the Community edition of MS Visual Studio.

Note: Although the Community edition of MSVC is free, to use the IDE for more than a 30-day trial period you must create a Microsoft account. If you will only compile using the command line, you don't need the IDE and thus no Microsoft account.

As a free and OpenSource alternative IDE you can use KDevelop. You can use KDevelop to modify and write C++ code but must use the command line to compile.

Optional system path configuration

Optionally you can include the paths to some folders to the system PATH variable. This is helpful if you want to access programs in these folders from the command line/powershell or if you want special programs to be found by the compiler or CMake. Besides this, adding folders to the PATH might be necessary if you did not use the corresponding options when installing the program.

  • You can include the folder of your LibPack in your system PATH variable. This is useful if you plan to build multiple configurations/versions of LabRPS.
  • If you did not use the option to add CMake to the PATH while installing it, add its installation folder

C:\Program Files\CMake\bin to the PATH.

  • If you did not use the option to add TortoiseGit to the PATH while installing it, add its installation folder

C:\Program Files\TortoiseGit\bin to the PATH.

To add folder paths to the PATH variable:

  1. In the Windows Start menu Right click on Computer and choose Properties.
  2. In the appearing dialog click on Advanced system settings.
  3. Another dialog will open. Click there in the tab Advanced on Environment Variables.
  4. Again another dialog will open. Select then the variable Path and click on Edit.
  5. And again another dialog will open. Click there on New and add to path to the folder of Git or the LibPack.
  6. Finally press OK and close all dialogs by pressing OK as well.

Configuration

Once you have all of the necessary tools, libraries, and LabRPS source code, you are ready to begin the configuration and compilation process. This process will proceed in five steps:

  1. Run CMake once to examine your system and begin the configuration progress (this will report that it failed).
  2. Adjust necessary CMake settings to set the locations of the LibPack and enable Qt5.
  3. Re-run CMake to finalize the configuration (this time it should succeed).
  4. Use CMake to generate the Visual Studio build system.
  5. Use Visual Studio to build LabRPS.

CMake

First, configure the build environment using CMake:

  1. Open the CMake GUI
  2. Specify the source folder of LabRPS.
  3. Specify a build folder. This can be build in the folder you cloned the repo because this path is ignored by git. Do not use the source folder. CMake will create this folder if it does not exist.
  4. Click Configure.
  5. In the dialog that appears specify the generator you want to use: in most cases you will use the defaults in this dialog. For the standard MS Visual Studio use Visual Studio xx 2yyy where xx is the compiler version and 2yyy the year of its release. It is recommended to use the default option Use default native compilers.

Note: It is important to specify the correct bit variant. If you have the 64-bit variant of the LibPack you must also use the x64 compiler.

This will begin the configuration and will fail because of missing settings. This is normal, you have not yet specified the location of the LibPack. However, there are other failures that might occur that require some further action on your part.

If it fails with the message that Visual Studio could not be found, the CMake support in MSVC is not yet installed. To do this:

  1. Open the MSVC IDE
  2. Use the menu Tools → Get Tools and Features
  3. In the Workloads tab enable Desktop development with C++
  4. On the right side you should now see that the component Visual C++ tools for CMake will be installed.
  5. Install it.

If it fails with a message about the wrong Python version or missing Python, then:

  1. Use the "Search:" box in CMake to search for the string "Python"
  2. If you see there a path like C:/Program Files/Python38/python.exe, CMake recognized the Python that is already installed on your PC, but that version is not compatible with the LibPack. Since the LibPack includes a compatible version of Python, modify the following Python settings in CMake to its paths (assuming the LibPack is in the folder D:/LabRPS-build/LabRPSLibs_1_0_0_x64_VC2022):

File:CMake Python settings.png

If there is no error about Visual Studio or Python, everything is fine, but CMake does not yet know all necessary settings. Therefore now:

  1. Search in CMake for the variable LABRPS_LIBPACK_DIR and specify the location of the LibPack folder you downloaded earlier.
  2. Search for the variable BUILD_QT5 and enable this option.
  3. (If planning on running directly from the build folder such as for debugging) Search for and enable the following options:
    • LABRPS_COPY_DEPEND_DIRS_TO_BUILD
    • LABRPS_COPY_LIBPACK_BIN_TO_BUILD
    • LABRPS_COPY_PLUGINS_BIN_TO_BUILD
  4. Click Configure again.

There should now be no errors. If you continue to encounter errors that you cannot diagnose, visit the Install/Compile forum on the LabRPS forum website. If CMake proceeded correctly, click on Generate. After this is done you can close CMake and start the compilation of LabRPS using Visual Studio. However, for the first compilation keep it open in case you want or need to change some options for the build process.

Options for the build process

The CMake build system gives you control over some aspects of the build process. In particular, you can switch on and off some features or modules using CMake variables.

Here is a description of some of these variables:

Variable name Description Default
BUILD_XXX Build LabRPS with the component XXX. If you don't want/need to compile e.g. the workbench Plot, disable the variable BUILD_PLOT. LabRPS will then not have this workbench.

Note: Some components are required for other components. If you for example uncheck BUILD_WEB CMake will inform you that then the component BUILD_START cannot be compiled correctly. Therefore check the CMake output after you changed a BUILD_XXX option!

depends
BUILD_ENABLE_CXX_STD The version of the C++ language standard. At least C++17 is required for LabRPS 0.1.0. depends
BUILD_DESIGNER_PLUGIN To build the Qt Designer plugin, see this section below OFF
CMAKE_INSTALL_PREFIX The output folder when building the target INSTALL, see also the section Running and installing LabRPS Windows default program installation folder
LABRPS_COPY_DEPEND_DIRS_TO_BUILD Copies depending libraries needed to execute the LabRPS.exe to the build folder. See also the section Running and installing LabRPS.
Note: the options LABRPS_COPY_XXX only appear if the libraries were not already copied. If you want to bring back the options for some reason, you need to delete all folders in your build folder, except for the LibPack folder. In CMake delete the cache and start as if you compile for the first time.
OFF
LABRPS_COPY_LIBPACK_BIN_TO_BUILD Copies the LibPack binaries needed to execute the LabRPS.exe to the build folder. See also the section Running and installing LabRPS. OFF
LABRPS_COPY_PLUGINS_BIN_TO_BUILD Copies Qt's plugin files needed to execute the LabRPS.exe to the build folder. See also the section Running and installing LabRPS. OFF
LABRPS_LIBPACK_USE Switch the usage of the LabRPS LibPack on or off ON
LABRPS_LIBPACK_DIR Directory where the LibPack is LabRPS's source code folder
LABRPS_RELEASE_PDB Create debug libraries (*.pdb) also for release builds. It doesn't affect the speed (like a real debug build would do) and can be very useful to locate crashes in LabRPS code. In case LabRPS crashes a crash.dmp file will be created that can be loaded with MSVC and if you have the corresponding PDB files plus the source code of that version you can debug through the code. Without the PDB files it's not possible to debug the code and all what the debugger shows is the name of the DLL where the crash has occurred. ON
LABRPS_USE_MP_COMPILE_FLAG Adds the /MP (multiprocessor) option to the Visual Studio projects, enabling speedups on multi-core CPUs. This can greatly accelerate builds on modern processors.
Note: If you turn off LABRPS_USE_PCH, the compilation can quickly overload your heap space, even if you have 16 GB RAM.
ON
LABRPS_USE_PCH Precompiles the headers in order to save compilation time. ON
LABRPS_USE_PYBIND11 Includes the PyBind11 library. Note: after turning it on you might get a configuration error. Just configure again and the problem should go away. OFF

Building LabRPS

Depending on your compiler, the process for building LabRPS will be slightly different. In the following sections known workflows are described. If you want to build with Qt Creator, it is possible but it has not been tested, otherwise proceed directly:

Building from cmd.exe command line

If you want to build from the command line, CMake output will show you the proper command to run (which depends on the configured release directory). But this command will produce a Debug build which does not work on Windows and results in a Numpy import error in LabRPS (which is a known issue but hard to fix). You need to specify the --config Release option to force a Release build:

cmake --build E:/release --config Release

Please note that setting CMake variables like CMAKE_BUILD_TYPE does not have any effect, only specifying the --config option as shown above works.

Building with Visual Studio 17 (2022) or newer

Release Build

  1. Start the Visual Studio IDE. This can either be done by pressing the button Open Project in the CMake GUI or by double-clicking on the file LabRPS.sln that you find in your build folder.
  2. In the toolbar of the MSVC IDE assure that you use for the first compilation Release.
  3. There is a window called Solution Explorer. It lists all possible compilation targets. To start a full compilation, right-click on the target ALL_BUILD and then choose Build.

This will now take quite a long time.

To compile a ready-to use LabRPS, compile the target INSTALL, see the section Running and installing LabRPS.

If you don't get any errors you are done. Congratulations! You can exit MSVC or keep it open.

Debug Build

For a debug build it is necessary that the Python is used that is included in the LibPack. To assure this:

  1. Search in the CMake GUI for "Python"
  2. If you see there a path like C:/Program Files/Python38/python.exe, CMake recognized the Python that is installed on your PC and not the one of the LibPack. In this case adapt these different Python settings in CMake to this (assuming the LibPack is in the folder D:\LabRPS-build\LabRPSLibs_1.0.0_x64_VC17):

File:CMake Python settings.png

As prerequisite for the debug build, you need to do this:

  1. Copy the content of the LibPack folder bind to the bin folder of the LabRPS build folder (overwrite the existing files).
  2. Copy the content of the LibPack folder libd to the lib folder of the LabRPS build folder.

Now you can compile:

  1. Start the Visual Studio IDE. This can either be done by pressing the button Open Project in the CMake GUI or by double-clicking on the file LabRPS.sln that you find in your build folder.
  2. In the toolbar of the MSVC IDE assure that you use for the first compilation Debug.
  3. There is a window called Solution Explorer. It lists all possible compilation targets. To start a full compilation, right-click on the target ALL_BUILD and then choose Build in the context menu.

This will now take quite a long time.

If there were no compilation errors, and if the LABRPS_COPY_* options mentioned in the CMake Configuration step above were enabled, you can start the debug build:

  1. Right-click on the target LabRPSMain and then choose Set as Startup Project in the context menu.
  2. Finally click in the toolbar on the button with the green triangle named Local Windows Debugger.

This will start the debug build of LabRPS and you can use the MSVC IDE to debug it.

Command line build

The steps how to compile from the command line depends on the compiler. For MSVC 2022 the steps are:

  1. In Windows start menu go to Visual Studio 2022 → Visual Studio Tools and choose Developer Command Prompt for VS 2022
  2. Change to your build folder.
  3. Execute the command
msbuild ALL_BUILD.vcxproj /p:Configuration=Release

or

msbuild INSTALL.vcxproj /p:Configuration=Release

These steps can also be automaized. Here is for example a solution for MSVC 2022:

  1. Download the script compile-FC.txt.
  2. Rename it to compile-FC.bat
  3. In Windows file explorer Shift+Right-click on your build folder and use from the context menu Command prompt here.
  4. Execute the command
compile-FC install

Instead of calling compile-FC with the option install you can also use debug or release:

debug   - compile LabRPS in debug configuration

release - compile LabRPS in release configuration

install    - compile LabRPS in release configuration and create an install setup

Running and installing LabRPS

There are 2 methods to run the compiled LabRPS:

Method 1: You execute the LabRPS.exe that you find in your build folder in the subfolder bin

Method 2: You build the target INSTALL

Method 2 is the simpler one because it automatically assures that all libraries needed to run the LabRPS.exe are in the correct folder. The LabRPS.exe and the libraries will be output in the folder you specified in the CMake variable CMAKE_INSTALL_PREFIX.

For Method 1 you need to enable the LABRPS_COPY_* options mentioned in the CMake Configuration step above.

Troubleshooting

When running LabRPS you may encounter missing DLLs when using certain workbenches or features of workbenches. The error message in LabRPS's console will not tell you what DLL is missing. To find this out you must use an external tool:

import os
os.system(r"~\DependenciesGui.exe")

Note: Instead of the ~ you must specify the full path to the DependenciesGui.exe on your system.

  • Now drag in the *.pyd file of the workbench with which you get missing DLLs reported.

Updating the build

LabRPS is very actively developed. Therefore its source code changes almost daily. New features are added and bugs are fixed. To benefit from these source code changes, you must rebuild your LabRPS. This is done in two steps:

  1. Updating the source code
  2. Recompilation

Updating the source code

Using a frontend

When using the Git frontend TortoiseGit:

  1. Right-click on your LabRPS source code folder in the Windows file explorer and select Pull in the context menu.
  2. A dialog will appear. Select there what development branch you want to get. master is the main branch. Therefore use this unless you want to compile a special new feature from a branch that has not yet been merged to master. (For more about Git branches, see Git development process.)

Finally click OK.

Using the command line

Open a terminal (command prompt) and switch there to your source directory. Then type:

git pull https://github.com/LabRPS/LabRPS.git master

where master the the name of the main development branch. If you want to get code from another branch, use its name instead of master.

Tools

In order to join the LabRPS development you should compile and install the following tools:

Qt Designer plugin

LabRPS uses Qt as toolkit for its user interface. All dialogs are setup in UI-files that can be edited using the program Qt Designer that is part of any Qt installation and also included in the LibPack. LabRPS has its own set of Qt widgets to provide special features like adding a unit to input fields and to set preferences properties.

Compilation

The plugin cannot be loaded by the Qt Designer if it was compiled using another Qt version than the one your Qt Designer/Qt Creator is based on. Therefore the plugin must be compiled together with LabRPS:

  • In the CMake options (see this section above) enable the option BUILD_DESIGNER_PLUGIN and reconfigure.
  • open MSVC and build the target LabRPS_widgets

As result you will get the plugin file 'LabRPS_widgets.dll in the folder
~\src\Tools\plugins\widget\Release

Installation

To install the plugin, copy the DLL either to:

  • If you use the LibPack: to the folder
    ~\LabRPSLibs_1_0_0_x64_VC2022\plugins\designer
  • If you have a full Qt installation: you can choose between the folder
    C:\Qt\5.15.2\msvc2022_64\plugins\designer
    or
    C:\Qt\5.15.2\msvc2022_64\bin\designer (you must first create the designer subfolder.)
    (adapt the paths to your installation!).

Finally (re)start Qt Designer and check its menu Help → Plugins. If the plugin LabRPS_widgets.dll is listed as being loaded, you can now design and change LabRPS's .ui files. If not, you must compile the DLL by yourself.

If you prefer using Qt Creator instead of Qt Designer, the plugin file must be placed in this folder:
C:\Qt\Qt5.15.2\Tools\QtCreator\bin\plugins\designer
Then (re)start Qt Creator, switch to the mode Design and then check the menu Tools → Form Editor → About Qt Designer Plugins. If the plugin LabRPS_widgets.dll is listed as being loaded, you can now design and change LabRPS's .ui files. If not, you must compile the DLL by yourself.


Arrow-left.svg Previous: License