title: Undefined reference to posix_memalign in ARM GCC
body: <p>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. </p>
  
  <p>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.</p>
  
  <p>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 <a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0492c/BABFJDHC.html" rel="nofollow noreferrer">posix_memalign in stdlib.h</a>
  Error looks like that:</p>
  
  <p><a href="https://i.stack.imgur.com/7rEw4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7rEw4.png" alt="enter image description here"></a></p>
  
  <p>In my CMake file I have set my flags to </p>
  
  <pre><code>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")
  </code></pre>
  
  <p>Also I figure out, if I don't use flag -lc and -lrdimo, there will be undefined reference to _write(), _read(), _sbrk, _exit .....</p>
  
  <p>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". </p>