navit
navit copied to clipboard
Android build ignores compiler warning options, cluttering output
CMakeLists.txt
lines 851–865 set a bunch of compiler warning flags, notably -Wall
and -Wno-unused-parameter
.
For the Linux build that seems to work—I do get a few warnings, but none of those which are set to be suppressed.
However, the Android toolchain doesn’t seem to care about any of these—I keep getting unused parameter warnings (and others) all over the place.
The Linux build uses the GNU C compiler (version 9.3.0 on my system), whereas the Android build uses clang—do we need different settings for clang?
Partial output from a failed build while investigating #1043:
FAILED: /home/michael/tools/android-sdk-linux_86/ndk/21.0.6113669/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=armv7-none-linux-androideabi16 --gcc-toolchain=/home/michael/tools/android-sdk-linux_86/ndk/21.0.6113669/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/michael/tools/android-sdk-linux_86/ndk/21.0.6113669/toolchains/llvm/prebuilt/linux-x86_64/sysroot -DBIN_DIR=\"bin\" -DDEPENDS_ON_LIBICONV=1 -DENABLE_RELOCATABLE=1 -DHAVE_CONFIG_H=1 -DIMAGE_DIR=\"share/navit/icons\" -DIN_LIBINTL=1 -DIN_LIBRARY -DLIBDIR=\"/usr/local/lib/navit\" -DLIB_DIR=\"lib/navit\" -DLOCALE_ALIAS_PATH=LOCALEDIR -DLOCALE_DIR=\"share/locale\" -DMAN_DIR=\"share/man/man1\" -DMODULE=support_gettext_intl -DNO_XMALLOC -DSHARE_DIR=\"share/navit\" -DTEXTURE_DIR=\"share/navit/textures\" -Drelocate=libintl_relocate -Dset_relocation_prefix=libintl_set_relocation_prefix -I. -I../../../../../../ -I../../../../../ -Inavit -I../../../../../support -I../../../../../support/ezxml -I../../../../../support/glib -I../../../../../support/wordexp -I../../../../../support/gettext_intl -I../../../../../graphics/android -I../../../../../osd/core -I../../../../../vehicle/demo -I../../../../../gui/internal -I../../../../../map/binfile -I../../../../../map/mg -I../../../../../map/shapefile -I../../../../../map/textfile -I../../../../../map/csv -I../../../../../speech/android -I../../../../../traffic/dummy -I../../../../../traffic/null -I../../../../../traffic/traff_android -I../../../../../vehicle/android -I../../../../../fib-1.1 -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security -Wall -Wno-unused-parameter -Wno-sign-compare -Wno-missing-field-initializers -Wundef -Wcast-align -Wpointer-arith -Wextra -Wdate-time -Wmissing-prototypes -Wstrict-prototypes -Wformat-security -Werror=format-security -fstack-protector-strong -D_FORTIFY_SOURCE=2 -O0 -fno-limit-debug-info -fPIC -fPIC -MD -MT navit/support/gettext_intl/CMakeFiles/support_gettext_intl.dir/dcigettext.c.o -MF navit/support/gettext_intl/CMakeFiles/support_gettext_intl.dir/dcigettext.c.o.d -o navit/support/gettext_intl/CMakeFiles/support_gettext_intl.dir/dcigettext.c.o -c /home/michael/src/navit/navit/support/gettext_intl/dcigettext.c
and, somewhere later:
/home/michael/src/navit/navit/traffic/dummy/traffic_dummy.c:170:62: warning: unused parameter 'nav' [-Wunused-parameter]
static struct traffic_priv * traffic_dummy_new(struct navit *nav, struct traffic_methods *meth,
^
Conclusion:
- clang gets called with the correct
-W*
arguments -
-Wno*
does not seem to take any effect
If I comment out the line
add_compiler_flag_if_available("-Wall")
that still doesn’t make a difference (even disabled warnings still appear). However, changing the line to
add_compiler_flag_if_available("-w")
suppresses all warnings.
The documentation at https://clang.llvm.org/docs/DiagnosticsReference.html lists what warnings are available and how to enable them (some are enabled by default), but not how to suppress warnings (-Wnofoo
to suppress -Wfoo
is not mentioned anywhere). Does clang require a different syntax than gcc?
Hi @mvglasow, as you said, the majority of warnings come from -Wunused-parameter
, and it is indeed difficult to parse through Android build's output to make the difference between existing warnings and real errors.
Another option would be to use G_GNUC_UNUSED
whenever supported, for example, replacing:
static int navit_cmd_zoom_out(struct navit *this_, char *cmd, struct attr **in, struct attr ***out) {
with:
static int navit_cmd_zoom_out(struct navit *this_, G_GNUC_UNUSED char *cmd, G_GNUC_UNUSED struct attr **in, G_GNUC_UNUSED struct attr ***out) {
but obviously, this requires manual update of many function definitions and I am not sure the various compilers for all supported platforms currently support G_GNUC_UNUSED
(Android's NDK does)...
That would be a last resort to consider if nothing else works—though we have a total of three warnings we are trying to suppress. In any case, I’d like to figure out why clang seemingly ignores the command line options.
What is more puzzling, -Wunused-parameter
is not enabled by default as far as the clang docs are concerned, yet I get these warnings even after removing -Wall
.
According to the docs, clang warnings can also be controlled via pragmas—if command line options don’t work, another option would be to include our pragmas in some global header file (which I think we have already). As a side effect, we’d have to maintain our warnings settings in two places—once for gcc, once for clang.