Describe the bug
Trying to build the POSIX port, targeting Cygwin (v3.5.7) on Windows 11, there is a build error related to pthreads:
[ 7%] Building C object _deps/freertos_kernel-build/portable/CMakeFiles/freertos_kernel_port.dir/ThirdParty/GCC/Posix/port.c.obj
In file included from C:/Users/msatti/Development/GaugeSimulator/build/_deps/freertos_kernel-src/portable/ThirdParty/GCC/Posix/port.c:59:
C:/Users/msatti/Development/GaugeSimulator/build/_deps/freertos_kernel-src/portable/ThirdParty/GCC/Posix/port.c: In function ‘xPortStartScheduler’:
C:/Users/msatti/Development/GaugeSimulator/build/_deps/freertos_kernel-src/portable/ThirdParty/GCC/Posix/port.c:267:27: error: expected expression before ‘{’ token
267 | hSigSetupThread = PTHREAD_ONCE_INIT;
| ^~~~~~~~~~~~~~~~~
make[2]: *** [_deps/freertos_kernel-build/portable/CMakeFiles/freertos_kernel_port.dir/build.make:80: _deps/freertos_kernel-build/portable/CMakeFiles/freertos_kernel_port.dir/ThirdParty/GCC/Posix/port.c.obj] Error 1
make[1]: *** [CMakeFiles/Makefile2:1150: _deps/freertos_kernel-build/portable/CMakeFiles/freertos_kernel_port.dir/all] Error 2
make: *** [Makefile:101: all] Error 2
Caused by PTHREAD_ONCE_INIT not being a valid expression for assigning a value, which is defined as:
#define PTHREAD_ONCE_INIT { PTHREAD_MUTEX_INITIALIZER, 0 }
Note: glibc defines it as the following instead, which is a valid expression:
#define PTHREAD_ONCE_INIT (struct __pthread_once) { __PTHREAD_ONCE_INIT }
Target
- Toolchain and version: [e.g. x86-64-pc-cygwin (pthread.h from package cygwin-v3.5.7) / gcc-14.2]
Host
To Reproduce
- Compile the POSIX port via CMake for Cygwin.
Expected behavior
Build succeeds
Workaround by defining the following in FreeRTOSConfig.h:
#undef PTHREAD_ONCE_INIT
#define PTHREAD_ONCE_INIT (pthread_once_t) { PTHREAD_MUTEX_INITIALIZER, 0 }
Which gets included by port.c via the CMake config interface library.
Potential fix by something like (?):
pthread_once_t hSigSetupThread2 = PTHREAD_ONCE_INIT;
hSigSetupThread = hSigSetupThread2;
(Not familiar with usage of pthreads, is calling pthread_once() applicable?)
Thanks.
Describe the bug
Trying to build the POSIX port, targeting Cygwin (v3.5.7) on Windows 11, there is a build error related to pthreads:
Caused by
PTHREAD_ONCE_INITnot being a valid expression for assigning a value, which is defined as:Note: glibc defines it as the following instead, which is a valid expression:
Target
Host
To Reproduce
Expected behavior
Build succeeds
Workaround by defining the following in FreeRTOSConfig.h:
Which gets included by port.c via the CMake config interface library.
Potential fix by something like (?):
(Not familiar with usage of pthreads, is calling
pthread_once()applicable?)Thanks.