Main Content

Specify C/C++ Compilers for Testing in Polyspace Platform User Interface

This page lists the compilers supported for C/C++ testing with Polyspace® Test™. For information on compilers supported with the static analysis products, Polyspace Bug Finder™ and Polyspace Code Prover™, see Compilation toolchain (Static analysis) or -compiler (Polyspace Bug Finder).

You can author unit tests for C/C++ code in the Polyspace Platform user interface. However, before you begin, your source files must compile successfully with a supported compiler. This topic describes the compiler requirements, explains how to perform an initial quick setup, and shows how to configure any compiler of your choice to compile source files and tests.

Check Compiler Setup After Install

To analyze your source files and later build them, you require a compiler. If you have a supported compiler installed, it is automatically detected (except for MinGW, which requires additional setup). To see if a compiler has been detected:

  1. On the toolstrip, select Settings.

  2. On the Testing and Profiling tab, check the option C/C++ Host Compiler to see if a compiler has been detected.

When you parse code or build a Polyspace Platform project for the first time, this compiler is used during code analysis and project build.

For more information on supported compilers, see Supported Host Compilers. If you are using Polyspace Test on Windows® without a compiler previously installed, install MinGW in a path without spaces and set the environment variable MW_MINGW64_LOC to your install folder.

Most desktop Linux® distributions have GNU® C (GCC) installed by default and do not require additional setup for Polyspace Test.

Note that a supported compiler is required only to compile code generated by Polyspace Test during the build process. For compiling your sources and tests, you can continue to use any compiler that you are already using. For more information, see the next sections.

Host Compiler and User Compiler

When you build a Polyspace Platform project, the build happens in two steps. Each step uses a separate compiler specification.

  • The source code and tests are compiled into a test executable. You can compile the code and tests for on-host or on-target execution. The compiler being used for this step will be henceforth referred to as the user compiler.

  • A master executable is created from internally generated code to dispatch instructions to the test executable. This compilation step always happens on the host. The compiler being used for this step will be henceforth referred to as the host compiler.

For test execution on host, you can use the same compiler as the host compiler and user compiler.

Note that the initial parsing of the source code in a Polyspace Platform project uses the user compiler that you specified.

See Installed Host Compilers

If you have a supported host compiler installed, the compiler is automatically detected when you open the Polyspace Platform user interface. When you create a new project in the user interface, this compiler is also selected as the user compiler for parsing source code and building the project. If your compiler is not detected automatically, see Troubleshoot Missing Compiler Error.

To see the installed host compilers that Polyspace Test can detect currently, do one of the following:

  • In the Polyspace Platform user interface:

    1. On the toolstrip, select Settings.

    2. On the Testing and Profiling tab, see the automatically detected host compilers in the drop-down list for the option C/C++ Host Compiler.

  • At the command-line, enter:

    polyspace-test -manage-host-compiler -list
    For more information, see polyspace-test -manage-host-compiler.

Specify Compilers

If you have multiple supported compilers installed, you can change the compilers selected by default.

To specify the host compiler:

  1. On the Polyspace Platform toolstrip, select Settings.

  2. On the Testing and Profiling tab, select a compiler for the option C/C++ Host Compiler.

    If you do not see a compiler in this drop-down list, it indicates that a supported compiler was not detected. See Supported Host Compilers for installing and configuring a supported host compiler.

To specify the user compiler:

  1. On the Projects pane, double-click the Configuration node of your project.

    See also Configure Project for Testing in Polyspace Platform User Interface.

  2. On the Build tab, select the Target & Compiler node.

  3. Select an option for Compilation toolchain (Testing). By default, this list shows installed compilers that are supported for use as host compilers.

    If you want to use the same compiler as the host compiler and user compiler, select Detect automatically. The compilation then uses the host compiler specified in your settings. If you open this project on another machine with a different host compiler, the project will compile using the host compiler on that machine.

    You can add more compilers to the Compilation toolchain (Testing) list using one of these methods:

    • Create and register a target using a custom target registration file. The target registration file defines the toolchain that you want to use. For more information on:

    • Create a toolchain in the Polyspace Platform user interface by specifying build tool paths, directives, and other information in an app. For more information, see Toolchain.

      Note that you cannot create a full execution target in the toolchain app. Using this app, you can only create a toolchain to associate with host execution (that is, with Host Computer as board and processor), or link it to a board that you have registered separately using a target registration file.

Supported Host Compilers

Polyspace Test supports certain versions of the following compilers as host compilers. For more details on host compilers, see Host Compiler and User Compiler.

PlatformCompilers
Windows

Microsoft® Visual C++®, MinGW C/C++

Linux

GCC C/C++

macOS

Xcode

For the full list of supported compilers and compiler versions, see the Polyspace Test column in Supported and Compatible Compilers.

Compilers and Debugging

Debugging of tests on host requires that your host compiler and user compiler are the same. To avoid issues during debugging, you can follow this best practice:

  1. Create a build configuration variant in your project where the Compilation toolchain (Testing) is left to Detect automatically so that the user compiler is the same as the host compiler.

  2. When debugging, select this configuration variant and then continue the debugging workflow.

For more information on:

On Windows platforms, your choice of host compiler determines which debugger is used:

  • If you specify a Microsoft Visual C++ compiler as host compiler, when you run tests in debug mode, your tests open at predefined breakpoints in the Microsoft Visual Studio® IDE.

  • If you specify a MinGW compiler as host compiler, when you run tests in debug mode, your tests open at predefined breakpoints in Visual Studio Code (assuming you have installed the appropriate Visual Studio Code extension).

    For more information on installing the extension, see Debug Test Failures from Polyspace Platform User Interface.

Troubleshoot Missing Compiler Error

If a supported compiler is not detected, you see this error when parsing code or building a project in the Polyspace Platform user interface:

Supported C/C++ host compiler not found. Install a supported compiler.

If you encounter this error, check the following:

  • Make sure that you have installed a supported compiler and use this compiler for code analysis and building your tests. You might have to restart the Polyspace Platform user interface after installing a supported compiler.

  • Make sure that you have installed both a C and C++ compiler. For instance, if you install only the GNU C compiler so that you have access to the gcc command but not the g++ command, you cannot use the compiler as a host compiler.

  • If you have installed a supported compiler, check if you require additional setup for detection of the compiler.

    For most supported compilers, if installed, the compiler is detected automatically. Note the following:

    • In Windows, the MinGW compilers might not be detected automatically. If you have a MinGW compiler installed and the installation path is not detected automatically, set the environment variable MW_MINGW64_LOC to your MinGW installation folder. Note the following:

      • The MinGW installation folder must contain a bin subfolder that has executables such as gcc and mingw32-make. For instance, if you set the variable MW_MINGW64_LOC to C:\MyMinGW, there must be a subfolder C:\MyMinGW\bin that contains executables such as gcc and mingw32-make. Do not set the variable MW_MINGW64_LOC to the subfolder path.

      • The MinGW installation folder path must not contain spaces.

    • On macOS, if you have Xcode installed, it should be detected automatically. If you do not see Xcode detected, make sure that the environment variable DEVELOPER_DIR is appropriately set, for instance, to /Applications/Xcode14.2.0.app/Contents/Developer.

See Also

Topics