title: aligned_alloc not found for clang
body: <p>I am running the following version of clang on a Mac OS X host:</p>
  
  <pre><code>$ clang -v
  Apple LLVM version 8.1.0 (clang-802.0.42)
  </code></pre>
  
  <p>I have some code that uses the <code>aligned_alloc()</code> C11 function to allocate an aligned chunk of memory.</p>
  
  <p>I am compiling my binary with the <code>-std=c11</code> flag:</p>
  
  <pre><code>...
  clang -g -Wall -Wextra -mavx -std=c11 -D__USE_POSIX -D__STDC_CONSTANT_MACROS -D__STDINT_MACROS -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE=1 -O2 -c my_binary.c -o my_binary.o; \
  clang -g -Wall -Wextra -mavx -std=c11 -D__USE_POSIX -D__STDC_CONSTANT_MACROS -D__STDINT_MACROS -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE=1 -O2 my_binary.o -o my_binary -lm; \
  ...
  </code></pre>
  
  <p>I am including <code>stdlib.h</code> and adding POSIX flags. From <code>my_binary.h</code>:</p>
  
  <pre><code>...
  #ifndef _POSIX_C_SOURCE
  #define _POSIX_C_SOURCE 200809L
  #endif /* getline() support */
  
  #ifndef _XOPEN_SOURCE
  #define _XOPEN_SOURCE 600
  #endif /* aligned_alloc() support */
  
  #include &lt;stdlib.h&gt;
  ...
  </code></pre>
  
  <p>I get the following compilation warning:</p>
  
  <pre><code>my_binary.c:245:15: warning: implicit declaration of function 'aligned_alloc' is invalid in C99 [-Wimplicit-function-declaration]
  s-&gt;data = aligned_alloc(32, s-&gt;n * sizeof(*s-&gt;data));
  </code></pre>
  
  <p>Which follows with this error:</p>
  
  <pre><code>Undefined symbols for architecture x86_64:
    "_aligned_alloc", referenced from:
        _bs_initialize_signal_avx in my_binary.o
        _bs_copy_signal_avx in my_binary.o
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  make: *** [build] Error 1
  </code></pre>
  
  <p>What am I doing incorrectly with clang, such that compilation ignores the <code>std</code> C11 flag?</p>
  
  <p>I am able to compile without errors on a CentOS 7 (Linux) host with gcc 5.3.0 and glibc 2.22.</p>