I used the default Makefile to compile FreeType for a Windows PC, and the program works fine.
However, when I try to create my own CMakelists.txt
to compile FreeType for an ESP32 environment, many FreeType library .c
files show the same error. It's a macro defined in fterror.h
that the compiler preprocessor cannot recognize.
Since the same code compiles successfully on a Windows PC, and I traced the include to the already included fterror.h
in those FreeType library .c
files, the compiler should recognize this. However, it still gives the error "Missing fterror.h macro." As a result, the attempt to replace FT_ERR_PREFIX with FT_Err_ fails, causing numerous errors.
How can I fix this problem?
[2/200] Building C object esp-idf/freetype2/CMakeFiles/__idf_freetype2.dir/base/ftbdf.c.obj
FAILED: esp-idf/freetype2/CMakeFiles/__idf_freetype2.dir/base/ftbdf.c.obj
ccache C:\Users\CKan\.espressif\tools\xtensa-esp32s3-elf\esp-12.2.0_20230208\xtensa-esp32s3-elf\bin\xtensa-esp32s3-elf-gcc.exe -DESP_PLATFORM -DIDF_VER=\"v5.1-dirty\" -DSOC_MMU_PAGE_SIZE=CONFIG_MMU_PAGE_SIZE -D_GNU_SOURCE -D_POSIX_READER_WRITER_LOCKS -IC:/Projects/tgesp32/build/config -IC:/Projects/tgesp32/components/freetype2/include -IC:/Projects/tgesp32/components/freetype2/include/freetype -IC:/Projects/tgesp32/components/freetype2/include/freetype/config -IC:/Projects/tgesp32/components/freetype2/include/freetype/internal -IC:/Projects/tgesp32/components/freetype2/include/freetype/internal/services -IC:/Projects/tgesp32/components/freetype2/include/dlg -IC:/Users/CKan/esp/esp-idf/components/newlib/platform_include -IC:/Users/CKan/esp/esp-idf/components/freertos/FreeRTOS-Kernel/include -IC:/Users/CKan/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/include -IC:/Users/CKan/esp/esp-idf/components/freertos/esp_additions/include/freertos -IC:/Users/CKan/esp/esp-idf/components/freertos/esp_additions/include -IC:/Users/CKan/esp/esp-idf/components/freertos/esp_additions/arch/xtensa/include -IC:/Users/CKan/esp/esp-idf/components/esp_hw_support/include -IC:/Users/CKan/esp/esp-idf/components/esp_hw_support/include/soc -IC:/Users/CKan/esp/esp-idf/components/esp_hw_support/include/soc/esp32s3 -IC:/Users/CKan/esp/esp-idf/components/esp_hw_support/port/esp32s3/. -IC:/Users/CKan/esp/esp-idf/components/esp_hw_support/port/esp32s3/private_include -IC:/Users/CKan/esp/esp-idf/components/heap/include -IC:/Users/CKan/esp/esp-idf/components/log/include -IC:/Users/CKan/esp/esp-idf/components/soc/include -IC:/Users/CKan/esp/esp-idf/components/soc/esp32s3 -IC:/Users/CKan/esp/esp-idf/components/soc/esp32s3/include -IC:/Users/CKan/esp/esp-idf/components/hal/esp32s3/include -IC:/Users/CKan/esp/esp-idf/components/hal/include -IC:/Users/CKan/esp/esp-idf/components/hal/platform_port/include -IC:/Users/CKan/esp/esp-idf/components/esp_rom/include -IC:/Users/CKan/esp/esp-idf/components/esp_rom/include/esp32s3 -IC:/Users/CKan/esp/esp-idf/components/esp_rom/esp32s3 -IC:/Users/CKan/esp/esp-idf/components/esp_common/include -IC:/Users/CKan/esp/esp-idf/components/esp_system/include -IC:/Users/CKan/esp/esp-idf/components/esp_system/port/soc -IC:/Users/CKan/esp/esp-idf/components/esp_system/port/include/private -IC:/Users/CKan/esp/esp-idf/components/xtensa/include -IC:/Users/CKan/esp/esp-idf/components/xtensa/esp32s3/include -IC:/Users/CKan/esp/esp-idf/components/lwip/include -IC:/Users/CKan/esp/esp-idf/components/lwip/include/apps -IC:/Users/CKan/esp/esp-idf/components/lwip/include/apps/sntp -IC:/Users/CKan/esp/esp-idf/components/lwip/lwip/src/include -IC:/Users/CKan/esp/esp-idf/components/lwip/port/include -IC:/Users/CKan/esp/esp-idf/components/lwip/port/freertos/include -IC:/Users/CKan./esp/esp-idf/components/lwip/port/esp32xx/include -IC:/Users/CKan./esp/esp-idf/components/lwip/port/esp32xx/include/arch -mlongcalls -fdiagnostics-color=always -ffunction-sections -fdata-sections -Wall -Werror=all -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=unused-but-set-variable -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -Wno-sign-compare -Wno-enum-conversion -gdwarf-4 -ggdb -Og -fmacro-prefix-map=C:/Projects/tgesp32=. -fmacro-prefix-map=C:/Users/CKan./esp/esp-idf=/IDF -fstrict-volatile-bitfields -fno-jump-tables -fno-tree-switch-conversion -DconfigENABLE_FREERTOS_DEBUG_OCDAWARE=1 -std=gnu17 -Wno-old-style-declaration -MD -MT esp-idf/freetype2/CMakeFiles/__idf_freetype2.dir/base/ftbdf.c.obj -MF esp-idf\freetype2\CMakeFiles\__idf_freetype2.dir\base\ftbdf.c.obj.d -o esp-idf/freetype2/CMakeFiles/__idf_freetype2.dir/base/ftbdf.c.obj -c C:/Projects/tgesp32/components/freetype2/base/ftbdf.c
In file included from C:/Projects/tgesp32/components/freetype2/include/freetype/freetype.h:25,
from C:/Projects/tgesp32/components/freetype2/include/freetype/internal/ftdebug.h:30,
from C:/Projects/tgesp32/components/freetype2/base/ftbdf.c:19:
C:/Projects/tgesp32/components/freetype2/base/ftbdf.c: In function 'FT_Get_BDF_Charset_ID':
C:/Projects/tgesp32/components/freetype2/include/freetype/internal/ftdebug.h:329:36: error: 'FT_ERR_PREFIXInvalid_Face_Handle' undeclared (first use in this function); did you mean 'FT_Err_Invalid_Face_Handle'?
329 | #define FT_THROW( e ) FT_ERR_CAT( FT_ERR_PREFIX, e )
| ^~~~~~~~~~~~~
C:/Projects/tgesp32/components/freetype2/include/freetype/fttypes.h:596:30: note: in definition of macro 'FT_ERR_XCAT'
596 | #define FT_ERR_XCAT( x, y ) x ## y
| ^
C:/Projects/tgesp32/components/freetype2/include/freetype/internal/ftdebug.h:329:24: note: in expansion of macro 'FT_ERR_CAT'
329 | #define FT_THROW( e ) FT_ERR_CAT( FT_ERR_PREFIX, e )
| ^~~~~~~~~~
C:/Projects/tgesp32/components/freetype2/base/ftbdf.c:44:14: note: in expansion of macro 'FT_THROW'
44 | return FT_THROW( Invalid_Face_Handle );
| ^~~~~~~~
C:/Projects/tgesp32/components/freetype2/include/freetype/internal/ftdebug.h:329:36: note: each undeclared identifier is reported only once for each function it appears in
329 | #define FT_THROW( e ) FT_ERR_CAT( FT_ERR_PREFIX, e )
| ^~~~~~~~~~~~~
C:/Projects/tgesp32/components/freetype2/include/freetype/fttypes.h:596:30: note: in definition of macro 'FT_ERR_XCAT'
596 | #define FT_ERR_XCAT( x, y ) x ## y
| ^
C:/Projects/tgesp32/components/freetype2/include/freetype/internal/ftdebug.h:329:24: note: in expansion of macro 'FT_ERR_CAT'
329 | #define FT_THROW( e ) FT_ERR_CAT( FT_ERR_PREFIX, e )
| ^~~~~~~~~~
C:/Projects/tgesp32/components/freetype2/base/ftbdf.c:44:14: note: in expansion of macro 'FT_THROW'
44 | return FT_THROW( Invalid_Face_Handle );
| ^~~~~~~~
C:/Projects/tgesp32/components/freetype2/include/freetype/internal/ftdebug.h:329:36: error: 'FT_ERR_PREFIXInvalid_Argument' undeclared (first use in this function); did you mean 'FT_Err_Invalid_Argument'?
329 | #define FT_THROW( e ) FT_ERR_CAT( FT_ERR_PREFIX, e )
| ^~~~~~~~~~~~~
C:/Projects/tgesp32/components/freetype2/include/freetype/fttypes.h:596:30: note: in definition of macro 'FT_ERR_XCAT'
596 | #define FT_ERR_XCAT( x, y ) x ## y
| ^
C:/Projects/tgesp32/components/freetype2/include/freetype/internal/ftdebug.h:329:24: note: in expansion of macro 'FT_ERR_CAT'
329 | #define FT_THROW( e ) FT_ERR_CAT( FT_ERR_PREFIX, e )
| ^~~~~~~~~~
C:/Projects/tgesp32/components/freetype2/base/ftbdf.c:51:15: note: in expansion of macro 'FT_THROW'
51 | error = FT_THROW( Invalid_Argument );
| ^~~~~~~~
C:/Projects/tgesp32/components/freetype2/base/ftbdf.c: In function 'FT_Get_BDF_Property':
C:/Projects/tgesp32/components/freetype2/include/freetype/internal/ftdebug.h:329:36: error: 'FT_ERR_PREFIXInvalid_Face_Handle' undeclared (first use in this function); did you mean 'FT_Err_Invalid_Face_Handle'?
329 | #define FT_THROW( e ) FT_ERR_CAT( FT_ERR_PREFIX, e )
| ^~~~~~~~~~~~~
C:/Projects/tgesp32/components/freetype2/include/freetype/fttypes.h:596:30: note: in definition of macro 'FT_ERR_XCAT'
596 | #define FT_ERR_XCAT( x, y ) x ## y
| ^
C:/Projects/tgesp32/components/freetype2/include/freetype/internal/ftdebug.h:329:24: note: in expansion of macro 'FT_ERR_CAT'
329 | #define FT_THROW( e ) FT_ERR_CAT( FT_ERR_PREFIX, e )
| ^~~~~~~~~~
C:/Projects/tgesp32/components/freetype2/base/ftbdf.c:76:14: note: in expansion of macro 'FT_THROW'
76 | return FT_THROW( Invalid_Face_Handle );
| ^~~~~~~~
C:/Projects/tgesp32/components/freetype2/include/freetype/internal/ftdebug.h:329:36: error: 'FT_ERR_PREFIXInvalid_Argument' undeclared (first use in this function); did you mean 'FT_Err_Invalid_Argument'?
329 | #define FT_THROW( e ) FT_ERR_CAT( FT_ERR_PREFIX, e )
| ^~~~~~~~~~~~~
C:/Projects/tgesp32/components/freetype2/include/freetype/fttypes.h:596:30: note: in definition of macro 'FT_ERR_XCAT'
596 | #define FT_ERR_XCAT( x, y ) x ## y
| ^
C:/Projects/tgesp32/components/freetype2/include/freetype/internal/ftdebug.h:329:24: note: in expansion of macro 'FT_ERR_CAT'
329 | #define FT_THROW( e ) FT_ERR_CAT( FT_ERR_PREFIX, e )
| ^~~~~~~~~~
C:/Projects/tgesp32/components/freetype2/base/ftbdf.c:79:14: note: in expansion of macro 'FT_THROW'
79 | return FT_THROW( Invalid_Argument );
| ^~~~~~~~
I got the way to resolve this preprocessing error during compilation:
In fterror.h
the FT_ERR_PREFIX
is defined as FT_Err_
but at the end of the header it undefines it if FT2_BUILD_LIBRARY
is not defined.
So, I need to define this macro in order to keep the FT_ERR_PREFIX
from being undefined by adding to CMakelists.txt the following:
add_definitions(-DFT2_BUILD_LIBRARY)