I am using (STM32F407VG-Discovey board) with compiler "gcc-arm-none-eabi-7-2017-q4-major" (arm-none-eabi-gcc) and I am trying to implement "google project flatbuffers". That needs for running time library malloc.h, and also heap memory.
I turn on heap memory on my ARM processor and tested it with include and and try basic operation calling malloc function. All works fine.
Now I include google flatbuffers header files and now I get error "undefined reference to `posix_memalign'". My linker can't find this function. It doesn't find but it should already have it posix_memalign in stdlib.h Error looks like that:
In my CMake file I have set my flags to
SET(CMAKE_C_FLAGS "-mthumb -fno-builtin -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -Wall -std=gnu11 -ffunction-sections -fdata-sections -fomit-frame-pointer -mabi=aapcs -fno-unroll-loops -ffast-math -ftree-vectorize -lc -lrdimon" CACHE INTERNAL "c compiler flags")
Also I figure out, if I don't use flag -lc and -lrdimo, there will be undefined reference to _write(), _read(), _sbrk, _exit .....
Explanation why this is not duplicate: I know adding, linker library with CMake you execute command target_link_libraries(). Problem here is that for non trivial reason my liner will not find posix_memalign function. But it will find other functions like malloc, alloc, free, ... They all are in "stdlib.h".
At ARM ToolChain official site under section 6.5.5. Alignment of C heap storage, it said for usage of function `posix_memalign´ you must use standard C99 not C11 as I have set.
So you must add in your CMAKE_C_FLAGS this flag: -std=c99
If you have set flag -std=c11 you should remove it.