title: using c11 standard with clang for use of strcpy_s
body: <p>I'm running OS X Sierra and trying to compile a c program that uses <code>strcpy_s</code>, but my installed clang compiler is using the c99 standard, but <a href="https://embeddedgurus.com/barr-code/2017/08/cs-strcpy_s-c11s-more-secure-version-of-strcpy/" rel="nofollow noreferrer">from what I've read</a> strcpy_s requires c11. </p>
  
  <p>Here's the code I'm trying to compile</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt; 
  
  int main(void)
  {
      char source[] = "Test string";
      char destination[50];
      if(strcpy_s(destination, sizeof(destination), source))
          printf("string copied - %s",destination);
  
      return 0;
  }
  </code></pre>
  
  <p>And here's the command I'm using to compile</p>
  
  <pre><code>$ clang copytest.c -o copytest
  copytest.c:11:5: warning: implicit declaration of function 'strcpy_s' is invalid in C99 [-Wimplicit-function-declaration]
          if(strcpy_s(copied_string, sizeof(copied_string), source))
             ^
  1 warning generated.
  Undefined symbols for architecture x86_64:
    "_strcpy_s", referenced from:
        _main in copytest-e1e05a.o
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  </code></pre>
  
  <p>I've tried compiling with the standard flag...</p>
  
  <p><code>clang -std=c11 copytest.c -o copytest</code> </p>
  
  <p>but I get the same exact "invalid in c99" warning. I've also tried compiling with gcc instead, and I still get the same c99 warning. </p>
  
  <p>I tried upgrading via homebrew which shows the following</p>
  
  <blockquote>
    <p>Warning: gcc 9.2.0 is already installed and up-to-date</p>
  </blockquote>
  
  <p>I have clang version 9.0.0</p>
  
  <pre><code>$ clang -v
  Apple LLVM version 9.0.0 (clang-900.0.39.2)
  </code></pre>
  
  <p>My xcode version is Xcode 9.2, which from everything I've read should come with c11 support. </p>
  
  <p>Am I doing something wrong with the compiling, is my code itself incorrect? <a href="https://stackoverflow.com/questions/30408197/how-to-compile-with-c11-standard-library-on-os-x-with-clang">This</a> is the only similar question I found on here, but it didn't even have an answer. Thanks</p>