Troubleshoot Issues Configuring Polyspace Using JSON Compilation Databases
Issue
You can generate a Polyspace® project or options file from a JSON compilation database using the command:
polyspace-configure -compilation-database <compileCommandFile>.json [<options>]
<compileCommandFile>.json
is a JSON compilation database file describing the compilation commands used in your build system.If the polyspace-configure
command cannot find the path to your compiler executable using the JSON file, you might see errors such as the following:
Binary: <compilerExec> not found relative to directory nor in the PATH environment variable.
<compilerExec>
is a compiler executable name such as gcc
.Possible Solutions
The polyspace-configure
command reads the "command"
entries in a JSON compilation database to determine the compilation commands. If you can execute the content of this entry directly at the command line without errors, in most cases, the polyspace-configure
command can find your compiler paths from the JSON compilation database. To troubleshoot the error, consider reasons why the "command"
entry in your JSON
compilation database file might not be executable.
Add Compiler Executable Path to JSON File or PATH
Variable
Consider the following snippet from a JSON compilation database:
[
{ "directory": "/home/user/build",
"command": "/usr/bin/gcc-8.1/bin/gcc -o file1.o file1.c",
"file": "file2.c" }
]
gcc
compiler executable is provided in the "command"
entry. The polyspace-configure
command does not require additional information to determine the compiler executable path.Now consider the following snippet where the full path to the gcc
executable is not directly given as part of the command:
[
{ "directory": "/home/user/build",
"command": "gcc -o file1.o file1.c",
"file": "file2.c" }
]
gcc
compiler command, the polyspace-configure
command first looks in the content of the directory
entry (/home/user/build
in this example) and then looks in folders specified in the PATH
environment variable of your operating system. To resolve the issue of untraceable compiler paths, in most cases, it is sufficient to add the path to the
gcc
executable to one of these places.Fix Environment Mismatch Between Compilation Command and polyspace-configure
Command
Sometimes, the issue of untraceable compiler paths indicates an environment mismatch between the locations where you run your compilation and the polyspace-configure
command. For instance, you might be running your compilation on a terminal where the PATH
environment variable is augmented temporarily, but you might later run polyspace-configure
on a terminal where this augmentation does not happen.
For example, you might generate your JSON compilation database file with compilation commands meant to run from the Visual Studio® developer prompt. However, you might later run polyspace-configure
on this compilation database file from the regular Windows® command line, leading to a mismatch in the environments.
The simplest way to detect environment mismatches is to copy the content of the "command"
entry, remove any \\
characters used for escaping inside JSON values, and execute the resulting command directly at the command line. If you can execute the command on a particular terminal without errors, you must also run polyspace-configure
on the same terminal so that it can use the environment variables preset on the terminal to
determine the compiler executable location.