vApplicationIdleHook, error: 'nested extern declaration'

Hey

I am trying to build FreeRTOS in our project, where we uses the vApplicationIdleHook.
When we build we are using a lot of ‘-Wxxx’ compiler flags to catch as many errors as possible.

My issue is when i build the project with this flag, i get the following error:

…\FreeRTOS\Sources\tasks.c:3476:29
error: nested extern declaration of vApplicationIdleHook [-Werror=nested-externs]

I need ideas to fix this issue. Other than dropping the compiler flag “-Werror”.

Did you declare it in your code again ? The declaration is already in task.h.
BTW when posting code references you should either post the exact FreeRTOS version you’re using or the relevant code snippet preferably enclosed by 3 tildes or backticks.

It is declared only here - FreeRTOS-Kernel/include/task.h at main · FreeRTOS/FreeRTOS-Kernel · GitHub. As @hs2 asked, did you declare this function elsewhere? If not, can you share which FreeRTOS version and compiler are you using? Also, please share the complete compiler output?

First, the “nested extern declaration” is a stylistic warning, not something that is a likely error unless your code tries to follow the style implied. It means that a forward declaration of a function is made locally within a function, instead of the stylistic preference of in a header file, or at least at the beginning of the source file outside all functions. This is a purely stylistic decision.

Second, my guess is that you are using an older version of FreeRTOS, as that declaration was removed a while ago as the various hook function declarations were moved to header files.

The kernel version i found in FreeRTOS.h file are 10.4.3, so yeah not the newest…

Here are the full output from a clean build. Are using WAF to build(Cmake lookalike)

chcp 1252 && ../waf/waf.bat configure build --condition=release --protocol=EthernetIP --target=Motor 

Active code page: 1252
Loaded WAF options from project.
Setting top to                           : C:\Users\abj\JVL\smc67\Software 
Setting out to                           : C:\Users\abj\JVL\smc67\Software\build 
Hilscher Waf version                     : 1.10.1.0 
Checking for waf version in 1.6.11-1.7.0 : ok 
Checking for program patch               : not found 
Checking for program git                 : C:\Program Files\Git\cmd\git.exe 
Checking for program Python 2.7          : C:\ProgramData\Hilscher GmbH\netX Studio CDT\BuildTools\python\2.7.11\python.exe
Checking for hboot image compiler        : C:\Users\abj\JVL\smc67\Software\WAF\hboot_image_compiler 
Checking for app intflash image update tool : C:\Users\abj\JVL\smc67\Software\WAF\hboot_image_compiler\netx90_app_iflash_image.py 
Checking for app image update tool          : C:\Users\abj\JVL\smc67\Software\WAF\hboot_image_compiler\netx90_app_image.py 
Checking for program arm-none-eabi-ar       : C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.10\bin\arm-none-eabi-ar.exe 
Checking for program arm-none-eabi-readelf  : C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.10\bin\arm-none-eabi-readelf.exe 
Checking for program arm-none-eabi-objdump  : C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.10\bin\arm-none-eabi-objdump.exe 
Checking for program arm-none-eabi-objcopy  : C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.10\bin\arm-none-eabi-objcopy.exe 
Checking for program arm-none-eabi-strip    : C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.10\bin\arm-none-eabi-strip.exe 
Checking for program arm-none-eabi-nm       : C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.10\bin\arm-none-eabi-nm.exe 
Checking for program arm-none-eabi-gcc      : C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.10\bin\arm-none-eabi-gcc.exe 
Checking for program arm-none-eabi-g++      : C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.10\bin\arm-none-eabi-g++.exe 
Toolchain 'gccarmemb'                       : gcc 10.3.1 
'configure' finished successfully (0.170s)
Waf: Entering directory `C:\Users\abj\JVL\smc67\Software\build\release/SMC67'
[  1/157] [ASM]       Components\CMSIS\Device\Hilscher\netx\Source\GCC\startup_netx90_a...
[  2/157] [CC]        Components\CMSIS\Device\Hilscher\netx\Source\system_netx.c
[  3/157] [CC]        Components\Commands\DPMSystem\Sources\DPMSystem_Handler.c
[  4/157] [CC]        Components\Commands\DPMSystem\Sources\DPMSystem_ExternFlash.c
[  5/157] [CC]        Components\Commands\DPMSystem\Sources\DPMSystem_FDL.c
[  6/157] [CC]        Components\Commands\FastMAC\sources\FastMAC.c
[  7/157] [CC]        Components\Commands\FastMAC\sources\FastMAC_Functions.c
[  8/157] [CC]        Components\Commands\SMC67_CMD\Sources\SMC67_cmd.c
[  9/157] [CC]        Components\Commands\tsk_cmd\Sources\tsk_Cmd.c
[ 10/157] [CC]        Components\Debug\Sources\tsk_Debug.c
[ 11/157] [CC]        Components\Encoder\Sources\Encoder.c
[ 12/157] [CC]        Components\Encoder\Sources\Encoder_calibrate.c
[ 13/157] [CC]        Components\EthernetApp\Sources\EthernetApp.c
[ 14/157] [CC]        Components\EthernetApp\Sources\EthernetAppFunctions.c
[ 15/157] [CC]        Components\EthernetApp\Sources\EthernetAppPktComm.c
[ 16/157] [CC]        Components\EthernetApp\Sources\EthernetAppPktSys.c
[ 17/157] [CC]        Components\Event_task\Source\Event_tsk.c
[ 18/157] [CC]        Components\Event_task\Source\Event_tsk_FRAM.c
[ 19/157] [CC]        Components\Event_task\Source\Event_tsk_ADC.c
[ 20/157] [CC]        Components\Event_task\Source\Event_tsk_Log.c
[ 21/157] [CC]        Components\Event_task\Source\Event_tsk_Update.c
[ 22/157] [CC]        Components\Event_task\Source\Event_tsk_Password.c
[ 23/157] [CC]        Components\FileMON\Sources\FileMON.c
[ 24/157] [CC]        Components\FreeRTOS\Sources\list.c
[ 25/157] [CC]        Components\FreeRTOS\Sources\queue.c
[ 26/157] [CC]        Components\FreeRTOS\Sources\tasks.c
[ 27/157] [CC]        Components\FreeRTOS\Sources\timers.c
[ 28/157] [CC]        Components\FreeRTOS\Sources\event_groups.c
[ 29/157] [CC]        Components\FreeRTOS\Sources\stream_buffer.c
..\..\..\Components\FreeRTOS\Sources\tasks.c: In function 'prvIdleTask[ 30/157] [CC]        Components\FreeRTOS\Sources\portable\MemMang\heap_3.c
[ 31/157] [CC]        Components\FreeRTOS\Sources\portable\GCC\ARM_CM4F\port.c
':
..\..\..\Components\FreeRTOS\Sources\tasks.c:3476:29: [ 32/157] [CC]        Components\HardwareLayer_Netx\Sources\ADC.c
error: nested extern declaration of '[ 33/157] [CC]        Components\HardwareLayer_Netx\Sources\EventSPI.c
vApplicationIdleHook[ 34/157] [CC]        Components\HardwareLayer_Netx\Sources\CyclicSPI.c
' [[ 35/157] [CC]        Components\HardwareLayer_Netx\Sources\Debug_Leds.c
-Werror=nested-externs]
 3476 |                 extern void [ 36/157] [CC]        Components\HardwareLayer_Netx\Sources\Power_LED.c
vApplicationIdleHook[ 37/157] [CC]        Components\HardwareLayer_Netx\Sources\Netx_Timers.c
( void );
      |                             [ 38/157] [CC]        Components\HardwareLayer_Netx\Sources\Uart_Mactalk.c
^~~~~~~~~~~~~~~~~~~~
compilation [ 39/157] t[CC]        Components\HardwareLayer_Netx\Sources\Shared_IRQ.c
erminat[ 40/157] ed [CC]        Components\HardwareLayer_extern\MU_encoder\Sources\MU_encoder.c
due t[ 41/157] [CC]        Components\HardwareLayer_extern\FRAM\Sources\FRAM_64Kbit.c
[ 42/157] [CC]        Components\HardwareLayer_extern\TempSense\Sources\TempSense.c
o -Wfatal-[ 43/157] [CC]        Components\HardwareLayer_extern\FPGA_noncyclic\Sources\FPGA_noncy...
errors.
[ 44/157] [CC]        Components\HardwareLayer_extern\FPGA_noncyclic\Sources\FPGA_Funct...
cc1.exe: all warnings being treated as errors
Waf: Leaving directory `C:\Users\abj\JVL\smc67\Software\build\release/SMC67'
Build failed
 -> task in 'armv7em-none-eabi/10.3.1/FreeRTOS_thumb_objs' failed (exit status 1):
        {task 49190320: c tasks.c -> tasks.o}
['C:\\Program Files (x86)\\GNU Arm Embedded Toolchain\\10 2021.10\\bin\\arm-none-eabi-gcc.exe', '-Wall', '-Wextra', '-Wimplicit', '-Werror', '-Wfatal-errors', '-Wredundant-decls', '-Winit-self', '-Wpointer-arith', '-Wswitch', '-Wredundant-decls', '-Wreturn-type', '-Wnested-externs', '-Wformat=2', '-Wshadow', '-Wmissing-braces', '-Wduplicated-cond', '-Wnull-dereference', '-Wduplicated-branches', '-Wrestrict', '-Wno-missing-field-initializers', '-Wno-type-limits', '-Wno-packed-bitfield-compat', '-Wno-unused', '-Wno-address-of-packed-member', '-mlong-calls', '-mapcs', '-fno-common', '-mthumb', '-march=armv7e-m', '-mfpu=fpv4-sp-d16', '-mfloat-abi=hard', '-Os', '-ffunction-sections', '-fdata-sections', '-mno-unaligned-access', '-std=gnu99', '-IC:\\Users\\abj\\JVL\\smc67\\Software\\build\\release\\SMC67\\Components\\FreeRTOS\\Sources\\Includes', '-IC:\\Users\\abj\\JVL\\smc67\\Software\\Components\\FreeRTOS\\Sources\\Includes', '-IC:\\Users\\abj\\JVL\\smc67\\Software\\build\\release\\SMC67\\Components\\FreeRTOS\\Sources\\portable\\GCC\\ARM_CM4F', '-IC:\\Users\\abj\\JVL\\smc67\\Software\\Components\\FreeRTOS\\Sources\\portable\\GCC\\ARM_CM4F', '-IC:\\Users\\abj\\JVL\\smc67\\Software\\build\\release\\SMC67\\Components\\CMSIS\\Include', '-IC:\\Users\\abj\\JVL\\smc67\\Software\\Components\\CMSIS\\Include', '-IC:\\Users\\abj\\JVL\\smc67\\Software\\build\\release\\SMC67\\Components\\CMSIS\\Device\\Hilscher\\netx\\Include', '-IC:\\Users\\abj\\JVL\\smc67\\Software\\Components\\CMSIS\\Device\\Hilscher\\netx\\Include', '-IC:\\Users\\abj\\JVL\\smc67\\Software\\build\\release\\SMC67\\Components\\netx_drv\\Include\\csp', '-IC:\\Users\\abj\\JVL\\smc67\\Software\\Components\\netx_drv\\Include\\csp', '-IC:\\Users\\abj\\JVL\\smc67\\Software\\build\\release\\SMC67\\Components\\netx_drv', '-IC:\\Users\\abj\\JVL\\smc67\\Software\\Components\\netx_drv', '-IC:\\Users\\abj\\JVL\\smc67\\Software\\build\\release\\SMC67\\Components\\netx_drv\\Include', '-IC:\\Users\\abj\\JVL\\smc67\\Software\\Components\\netx_drv\\Include', '-DMOTOR=1', '-D_DEBUG=0', '-D_DEBUGREL=0', '-DJVL_ETHERNETIP=1', '-D_NETX_', '-D__NETX90', '-D__STACK_SIZE = 8192', '-D__HEAP_SIZE = 8192', '-D__STARTUP_CLEAR_BSS', '-D__START = main', '-DNDEBUG', '..\\..\\..\\Components\\FreeRTOS\\Sources\\tasks.c', '-c', '-o', 'Components\\FreeRTOS\\_armv7em-none-eabi\\10.3.1\\FreeRTOS_thumb_objs\\tasks.o']

Version 10.4.3 had this declaration inside the function which is what is causing this warning - FreeRTOS-Kernel/tasks.c at V10.4.3 · FreeRTOS/FreeRTOS-Kernel · GitHub. This was changed in the following PR - Move the prototype for vApplicationIdleHook to task.h. by tcpluess · Pull Request #600 · FreeRTOS/FreeRTOS-Kernel · GitHub.

You can either suppress this warning with -Wno-nested-externs or can update to the latest version.