Redefined types when using FreeRTOS+POSIX and GCC compiler (Linaro v6.3.1)

surialic wrote on Wednesday, May 22, 2019:


I’m using TI tools (Code Composer Studio and the RM57 Launchpad MCU). I added FreeRTOS+POSIX to my already working GCC + FreeRTOS project. After adding all include paths I got compiler errors saying that the types shown in the attachment were redefined in POSIX types.h/time.h and compiler types.h.

I added -iquote"${workspace_loc:/${ProjName}/include/FreeRTOS_POSIX}" to the compiler flags to make sure that the correct sys/types.h was included at the POSIX and library files. With this, every time “sys/types.h” is included with quotes the POSIX file will be used and every time <sys/types.h> is included with angle brackets the compiler library file will be used. However that did not fix the problem.

After analyzing the intermediate files from running the preprocessor only (-E) I was able to find out that almost all of the FreeRTOS+POSIX headers (time.h, pthread.h etc.) include both sys/types.h files and therefore they break. They do not include them explicitly but when going down the include chain they eventually get included. I had FreeRTOS+POSIX running on another project with a TI compiler and it was working as expected. However, I did not see a sys/types.h file in the TI compiler library files. The problem showed up when I migrated to GCC.

I realize that this could be a TI specific issue but still wanted to put it out there and see if someone has had the same problem.

Thank you,


1 Like

I see a similar problem.
What i am trying todo :
Building FreeRTOS + POSIXs lib with GCC for RISC V arch.

The issue I see :
Conflicting type definitions between GCC sys/types.h and FreeRTOS_POSIX/sys/types.h,

the stdio.h from GCC includes sys/types.h, so that is leading to the conflict, the freeRTOS code DOES NOT include GCC’s sys/types.h (NO use of #include<sys/types.h>)

Error :
CC posix_demo.c
In file included from …/Source/lib/FreeRTOS-Plus-POSIX/include/FreeRTOS_POSIX.h:47,
from posix_demo.c:76:
…/Source/lib/include/FreeRTOS_POSIX/sys/types.h:48:38: error: conflicting types for ‘clock_t’
48 | typedef uint32_t clock_t;
| ^~~~~~~
In file included from /opt/riscv64/riscv64-unknown-elf/include/stdio.h:61,
from posix_demo.c:73:
/opt/riscv64/riscv64-unknown-elf/include/sys/types.h:107:19: note: previous declaration of ‘clock_t’ was here
107 | typedef CLOCK_T clock_t;
| ^~~~~~~
In file included from …/Source/lib/FreeRTOS-Plus-POSIX/include/FreeRTOS_POSIX.h:47,
from posix_demo.c:76:
…/Source/lib/include/FreeRTOS_POSIX/sys/types.h:57:38: error: conflicting types for ‘clockid_t’
57 | typedef int clockid_t;
| ^~~~~~~~~
In file included from /opt/riscv64/riscv64-unknown-elf/include/stdio.h:61,
from posix_demo.c:73:
/opt/riscv64/riscv64-unknown-elf/include/sys/types.h:199:21: note: previous declaration of ‘clockid_t’ was here
199 | typedef __clockid_t clockid_t;
| ^~~~~~~~~

I have tried changing the posixconfigENABLE_CLOCK_T / ENABLE_CLOCKID_T in FreeRTOS_POSIX_portable_default.h

82 /**
83 * @name Enable typedefs of POSIX types.
84 *
85 * Set these values to 1 or 0 to enable or disable the typedefs, respectively.
86 * These typedefs should only be disabled if they conflict with system typedefs.
87 */
88 /@{ */
89 #ifndef posixconfigENABLE_CLOCK_T
90 #define posixconfigENABLE_CLOCK_T 1 /
< clock_t in sys/types.h */
91 #endif
92 #ifndef posixconfigENABLE_CLOCKID_T
93 #define posixconfigENABLE_CLOCKID_T 1 /**< clockid_t in sys/types.h */
94 #endif

If i have to use the type defs from GCC i.e include<sys/types.h>, then i will have to edit the freeRTOS source files to change - “FreeRTOS_POSIX/sys/types.h” to <sys/types.h> I dont think this will be a good approach

Please suggest how to resolve this issue. Thanks

I commented under James’ post here – Building FreeRTOS + POSIX with GCC for RISC V architecture

In general, POSIX threading standard defines a set of interfaces, and POSIX “compliant” systems can “optionally” implement whatever makes sense to the system. In our case, we scoped out these headers, and our implementation assumed types are defined in FreeRTOS_POSIX/sys/types.h. Some of the definitions in sys/types.h are similar across various systems. (Likely, time_t and clock_t.) The others in our implementation rely on FreeRTOS specific structures (e.g. pthread_*. )

In case of conflicting definitions, I would first figure out which implementation to use – toolchain specific or FreeRTOS+POSIX or mixed. And if FreeRTOS+POSIX is involved in project, user could configure which type definitions to use. Our intention is that user does not need to change source and/or FreeRTOS_POSIX_portable_default.h, types can be configured with an additional header file. Please see examples in FreeRTOS-Plus-POSIX/include/portable/<vendor>/<board>/. (In espressif and microchip, you’ll see we are not using default types.)

Hope this explains a little bit.