When compiling C code for the ARM Cortex-M0 microcontroller in ModelSim, you may encounter the error “unknown compiler option ‘-lint’”. This error occurs because ModelSim’s compiler wrapper mtiARM is trying to pass the -lint option to the underlying GNU compiler arm-none-eabi-gcc, but this particular version of gcc does not recognize that option.
What causes the “unknown compiler option ‘-lint’” error
The -lint option stands for “lint” and enables additional warnings about suspicious code constructs. It is meant for catching potential bugs and improving code quality. However, not all versions of gcc support this option out-of-the-box. The mtiARM compiler wrapper assumes the underlying gcc will accept -lint, but if your gcc is too old, you’ll get an error.
Specifically, arm-none-eabi-gcc versions earlier than 4.6 do not recognize the -lint option. But mtiARM tries to pass it regardless of your gcc version. So if you have an older gcc installed, you’ll see this error.
Determining your GCC version
To check your arm-none-eabi-gcc version, run the following command in your terminal: arm-none-eabi-gcc –version
This will print out information about your compiler including the release number. For example: arm-none-eabi-gcc (GCC) 4.3.3 Copyright (C) 2008 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Here we can see the version is 4.3.3, which is too old to recognize -lint. We need 4.6 or newer.
Updating the GCC Compiler
If you have an outdated GNU compiler, you’ll need to update it to fix this issue. Here are a few options for getting a newer GCC version:
- Download and install an updated toolchain from the ARM website or other sources
- Update your package manager’s ARM gcc package if available (e.g. apt-get install on Linux)
- Build gcc from source, which allows specifying the version
The simplest option is usually updating via your system’s package manager if a new enough version is available there. For example on Ubuntu/Debian: sudo apt-get update sudo apt-get install arm-none-eabi-gcc
This will fetch the latest gcc packaged for your system. Check the version again after updating to confirm it worked.
Disabling Lint in mtiARM
Alternatively, you can tell mtiARM not to pass the -lint option in the first place. This avoids the error without upgrading gcc.
To disable -lint, you need to modify the mtiARM configuration file. This is usually located at: /opt/modelsim_ase/win32aloem/mtiARM
Open the mtiARM file in a text editor, and find the following lines: arm_cc_options=”-c -Wall -Wextra -Wno-unused-parameter -mcpu=$(touchstone_mpu) -mlittle-endian -mthumb -mthumb-interwork $*:S:$*:ansi $*:I:$*:nostdinc -Wimplicit-function-declaration -Wstrict-prototypes -Wbad-function-cast -Wno-conversion -Wmissing-prototypes -Wno-sign-conversion -D_MTI_SIMULATOR_ -D__HAL__ -g” arm_cc_lint=”-lint”
Comment out the arm_cc_lint line by adding a # at the beginning: #arm_cc_lint=”-lint”
Save and close the file. Now mtiARM will no longer pass -lint to gcc, avoiding the error. You miss out on the extra warnings lint provides, but at least you can compile.
Proper ModelSim Configuration
ModelSim’s Cortex-M0 support package includes relatively old versions of the GNU toolchain that causes issues like this lint error. It’s best to point ModelSim to a newer compiler instead of relying on its built-in ones.
To do this, use the following steps:
- Download an up-to-date ARM embedded gcc toolchain from ARM or elsewhere.
- Make a note of the
bindirectory containing the executables.
- In ModelSim, go to Tools > Compile Options > Libraries
- Select mtiARM under Tool Name.
- In the Executable Path enter the path to the
bindirectory of your downloaded toolchain.
- Click Apply, then OK to save.
Now ModelSim will use those newer tools instead of its built-in outdated ones. This provides a robust solution without hacks like disabling lint.
Other compiler differences to note
Switching toolchain versions like this can lead to other compiler differences and inconsistencies. Here are some additional things to be aware of:
- Different warning levels and meanings
- Potential behavioral differences in some corner cases
- Support for different C language standards
- Different include directories and libraries
- Changes to optimization levels
So make sure to thoroughly test your code after switching compilers. Enable all warnings and fix any issues that arise to ensure your code compiles cleanly at the highest warning level. Pay close attention to any behavioral differences too.
Why use the -lint option?
Now that you know how to fix the -lint error, you may be wondering what benefit that option provides. The lint utility analyzes source code and flags suspicious usage that may indicate bugs or poor coding practices. This includes things like:
- Unused variables or functions
- Missing return statements in functions
- Incompatible pointer types
- Uninitialized variables
- Unused function return values
- Dead code
These warnings help improve code quality and prevent defects early. Lint was originally a standalone tool developed at Bell Labs in the late 70s. It was later incorporated directly into gcc with the -lint option.
While lint can produce many extraneous warnings, it is very useful during development. It catches a variety of issues that can lead to bugs or maintenance headaches down the line. The GCC implementation focuses on the highest value features from the original lint program.
Recommendations for robust C programming
Here are some tips for avoiding issues that lint and other analyzers can catch:
- Always initialize variables
- Check return values from functions and libraries
- Cast carefully to avoid incompatible types
- Enable strict prototyping if possible
- Avoid unused variables and dead code
- Use ALL warnings and fix warnings as errors
- Use static analysis tools like lint during development
Following best practices like these makes your C code more robust and portable. The lint option provides a useful warning system to catch many of these problems.
The “unknown compiler option ‘-lint'” error occurs when ModelSim tries to enable lint warnings on an older GCC version that does not support it. To fix, either update to a newer compiler or disable the -lint option in mtiARM. Using an updated compiler is generally the best solution, rather than disabling useful warnings from lint.
Lint provides valuable static analysis of code to catch bugs and suggest improvements. It is worth taking the time to upgrade compilers and enable the highest warning levels. This results in more stable and maintainable C code for microcontroller projects.